Module: SecurizeString::CipherMethods::ClassMethods
- Defined in:
- lib/securize_string/cipher_methods.rb
Overview
Adds class methods for OpenSSL::Cipher support, including AES encryption, via inclusion of SecurizeString::CipherMethods into a class.
Instance Method Summary collapse
-
#aes_keygen(key_len = 256) ⇒ Object
A convenience method for generating a random key and init vector for AES keys.
-
#cipher_keygen(cipher_name) ⇒ Object
A convenience method for generating random cipher keys and initialization vectors.
-
#supported_ciphers ⇒ Object
Returns a list of supported ciphers.
Instance Method Details
#aes_keygen(key_len = 256) ⇒ Object
A convenience method for generating a random key and init vector for AES keys. Defaults to a key length of 256.
33 34 35 |
# File 'lib/securize_string/cipher_methods.rb', line 33 def aes_keygen(key_len=256) return cipher_keygen("aes-#{key_len.to_i}-cbc") end |
#cipher_keygen(cipher_name) ⇒ Object
A convenience method for generating random cipher keys and initialization vectors.
25 26 27 28 29 |
# File 'lib/securize_string/cipher_methods.rb', line 25 def cipher_keygen(cipher_name) cipher = OpenSSL::Cipher.new(cipher_name) cipher.encrypt return [cipher.random_key, cipher.random_iv].map {|s| self.new(s)} end |
#supported_ciphers ⇒ Object
Returns a list of supported ciphers. These can be passed directly into the cipher methods.
19 20 21 |
# File 'lib/securize_string/cipher_methods.rb', line 19 def supported_ciphers return OpenSSL::Cipher.ciphers end |