Module: Configliere::Crypter
- Defined in:
- lib/configliere/crypter.rb
Overview
Encrypt and decrypt values in configliere stores
Constant Summary collapse
- CIPHER_TYPE =
"aes-256-cbc"
Class Method Summary collapse
-
.decrypt(iv_and_ciphertext, encrypt_pass, options = {}) ⇒ String
Decrypt the given string, using the key and iv supplied.
-
.encrypt(plaintext, encrypt_pass, options = {}) ⇒ String
Encrypt the given string.
Class Method Details
.decrypt(iv_and_ciphertext, encrypt_pass, options = {}) ⇒ String
Decrypt the given string, using the key and iv supplied
34 35 36 37 38 39 40 |
# File 'lib/configliere/crypter.rb', line 34 def self.decrypt iv_and_ciphertext, encrypt_pass, ={} cipher = new_cipher :decrypt, encrypt_pass, cipher.iv, ciphertext = separate_iv_and_ciphertext(cipher, iv_and_ciphertext) plaintext = cipher.update(ciphertext) plaintext << cipher.final plaintext end |
.encrypt(plaintext, encrypt_pass, options = {}) ⇒ String
Encrypt the given string
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/configliere/crypter.rb', line 17 def self.encrypt plaintext, encrypt_pass, ={} # The cipher's IV (Initialization Vector) is prepended (unencrypted) to # the ciphertext, which as far as I can tell is safe for our purposes: # http://www.ciphersbyritter.com/NEWS6/CBCIV.HTM cipher = new_cipher :encrypt, encrypt_pass, cipher.iv = iv = cipher.random_iv ciphertext = cipher.update(plaintext) ciphertext << cipher.final combine_iv_and_ciphertext(iv, ciphertext) end |