Class: Flashover::Crypto
- Inherits:
-
Object
- Object
- Flashover::Crypto
- Defined in:
- lib/flashover.rb
Instance Method Summary collapse
- #decrypt(ciphertext) ⇒ Object
- #encrypt(plaintext) ⇒ Object
-
#initialize(passphrase, salt) ⇒ Crypto
constructor
A new instance of Crypto.
Constructor Details
#initialize(passphrase, salt) ⇒ Crypto
Returns a new instance of Crypto.
118 119 120 121 122 |
# File 'lib/flashover.rb', line 118 def initialize(passphrase, salt) raise MaryPoppins.new("salt needs to be 8 chars long") unless salt.length == 8 @passphrase = passphrase @salt = salt end |
Instance Method Details
#decrypt(ciphertext) ⇒ Object
133 134 135 136 137 138 139 140 |
# File 'lib/flashover.rb', line 133 def decrypt ciphertext decryptor = OpenSSL::Cipher::Cipher.new 'AES-256-CBC' decryptor.decrypt decryptor.pkcs5_keyivgen(@passphrase, @salt) decrypted = decryptor.update ciphertext decrypted << decryptor.final end |
#encrypt(plaintext) ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'lib/flashover.rb', line 124 def encrypt plaintext encryptor = OpenSSL::Cipher::Cipher.new 'AES-256-CBC' encryptor.encrypt encryptor.pkcs5_keyivgen(@passphrase, @salt) encrypted = encryptor.update plaintext encrypted << encryptor.final end |