Class: EvpBytesToKey::Key

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#ivString



12
13
14
# File 'lib/evp_bytes_to_key/key.rb', line 12

def iv
  @iv
end

#iv_hexString



12
13
14
# File 'lib/evp_bytes_to_key/key.rb', line 12

def iv_hex
  @iv_hex
end

#keyString



12
13
14
# File 'lib/evp_bytes_to_key/key.rb', line 12

def key
  @key
end

#key_hexString



12
13
14
# File 'lib/evp_bytes_to_key/key.rb', line 12

def key_hex
  @key_hex
end