Class: EvpBytesToKey::Key
- Inherits:
-
Object
- Object
- EvpBytesToKey::Key
- Defined in:
- lib/evp_bytes_to_key/key.rb
Overview
This class is used to generate a new encryption key (and iv, if applicable) from a password in a way that is compatible with how the openssl command line utility generates keys and ivs. It emulates the logic of EVP_KeyToBytes from OpenSSL but is not a direct drop-in replacement because it does not support options like the number of rounds to use or the message digest algorithm to use.
Instance Attribute Summary collapse
-
#iv ⇒ String
readonly
The key or iv value in the named format.
-
#iv_hex ⇒ String
readonly
The key or iv value in the named format.
-
#key ⇒ String
readonly
The key or iv value in the named format.
-
#key_hex ⇒ String
readonly
The key or iv value in the named format.
Instance Method Summary collapse
-
#initialize(password = nil, salt = nil, bits = nil, iv_length = nil) ⇒ EvpBytesToKey::Key
constructor
Generate a key from a given password.
Constructor Details
#initialize(password = nil, salt = nil, bits = nil, iv_length = nil) ⇒ EvpBytesToKey::Key
Generate a key from a given password. This key is identical to the key generated by EVP_KeyToBytes() in the openssl command-line utility.
24 25 26 27 28 29 30 31 |
# File 'lib/evp_bytes_to_key/key.rb', line 24 def initialize(password = nil, salt = nil, bits = nil, iv_length = nil) @password = validate_password(password) @salt = validate_salt(salt) @bits = validate_bits(bits) @iv_length = validate_iv_length(iv_length) generate_key! end |
Instance Attribute Details
#iv ⇒ String
Returns the key or iv value in the named format.
12 13 14 |
# File 'lib/evp_bytes_to_key/key.rb', line 12 def iv @iv end |
#iv_hex ⇒ String
Returns the key or iv value in the named format.
12 13 14 |
# File 'lib/evp_bytes_to_key/key.rb', line 12 def iv_hex @iv_hex end |
#key ⇒ String
Returns the key or iv value in the named format.
12 13 14 |
# File 'lib/evp_bytes_to_key/key.rb', line 12 def key @key end |
#key_hex ⇒ String
Returns the key or iv value in the named format.
12 13 14 |
# File 'lib/evp_bytes_to_key/key.rb', line 12 def key_hex @key_hex end |