Class: Ccs::Encrypter
- Inherits:
-
Object
- Object
- Ccs::Encrypter
- Defined in:
- lib/ccs/encrypter.rb
Overview
Encrypts the given content for transmission. Uses AES-256 in CBC mode internally, with salting.
Instance Method Summary collapse
-
#call ⇒ String
Performs the actual encryption, returning base64-encoded ciphertext.
-
#initialize(passphrase, content, salt) ⇒ Encrypter
constructor
Constructs an Encrypter instance with given passphrase, content and salt.
Constructor Details
#initialize(passphrase, content, salt) ⇒ Encrypter
Constructs an Encrypter instance with given passphrase, content and salt. Salt must be exactly 8 characters long.
21 22 23 24 25 |
# File 'lib/ccs/encrypter.rb', line 21 def initialize(passphrase, content, salt) @passphrase = passphrase @content = content @salt = salt end |
Instance Method Details
#call ⇒ String
Performs the actual encryption, returning base64-encoded ciphertext.
30 31 32 33 34 35 36 37 |
# File 'lib/ccs/encrypter.rb', line 30 def call encryptor.pkcs5_keyivgen(@passphrase, @salt, 1) encrypted = encryptor.update(@content) encrypted << encryptor.final openssl_salted_ciphertext = 'Salted__' + @salt + encrypted Base64.strict_encode64(openssl_salted_ciphertext) end |