class Sodium::Password::Key::Create
- Sodium::Password::Key::Create
- Reference
- Object
Overview
Create a key for encryption with auto set parameters based on time.
Usage:
pwkc = Sodium::Password::Key::Create.new
# Take approximately 1 second to generate a key.
pwkc.tcost = 1.0
# Memory use will end up between `mem_min` and `mem_max`
pwkc.mem_min = 128 * 1024 * 1024 # 128M
pwkc.mem_max = 256 * 1024 * 1024 # 256M
kdf, params = pwkc.create_kdf pass
# Or
key, params = pwkc.create_key pass, 32
# Save params.[mode, ops, mem, salt, key_size] to derive the same key later.
# Or serialize `params.to_h`
Deriving a previously created key.
Usage:
pwkey = Sodium::Password::Key.from_params hash
# Or
pwkey = Sodium::Password::Key.new
pwkey.mode = Mode.parse serialized[:mode]
pwkey.ops = serialized[:ops]
pwkey.mem = serialized[:mem]
pwkey.salt = serialized[:salt]
key_size = serialized[:key_size]
kdf = pwhash.derive_kdf pass
# Or
key = pwkey.derive_key pass, key_size
Defined in:
sodium/password/create_key.crInstance Method Summary
- #create_kdf(pass, *, salt : Bytes | String | Nil = nil) : Tuple(Kdf, Params)
-
#create_key(pass : Bytes | String, key_size, *, salt : Bytes | String | Nil = nil) : Tuple(SecureBuffer, Params)
Returns a consistent key based on [salt, pass, key_size, mode] in a SecureBuffer and Params.
-
#mem_max : UInt64
Specified in bytes.
-
#mem_max=(mem_max : UInt64)
Specified in bytes.
-
#mem_min : UInt64
Specified in bytes.
-
#mem_min=(mem_min)
Specified in bytes.
- #mode : Mode
- #mode=(mode : Mode)
-
#tcost : Float64
Specified in seconds.
-
#tcost=(tcost)
Specified in seconds.
Instance Method Detail
def create_key(pass : Bytes | String, key_size, *, salt : Bytes | String | Nil = nil) : Tuple(SecureBuffer, Params)
#
Returns a consistent key based on [salt, pass, key_size, mode] in a SecureBuffer and Params.
Params are set to run in approximately #tcost
seconds.
Make sure you store Params
for later use with #derive_key.
def mem_max : UInt64
#
Specified in bytes. Currently defaults to 256M. May increase between version.
def mem_max=(mem_max : UInt64)
#
Specified in bytes. Currently defaults to 256M. May increase between version.
def mem_min : UInt64
#
Specified in bytes. Currently the libsodium default. May increase between version.
def mem_min=(mem_min)
#
Specified in bytes. Currently the libsodium default. May increase between version.