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
- .check_platform_can_encrypt! ⇒ Object
-
.decrypt(enc_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
.check_platform_can_encrypt! ⇒ Object
24 25 26 27 |
# File 'lib/configliere/crypter.rb', line 24 def self.check_platform_can_encrypt! return true unless PLATFORM_ENCRYPTION_ERROR raise PLATFORM_ENCRYPTION_ERROR.class, "Encryption broken on this platform: #{PLATFORM_ENCRYPTION_ERROR}" end |
.decrypt(enc_ciphertext, encrypt_pass, options = {}) ⇒ String
Decrypt the given string, using the key and iv supplied
53 54 55 56 57 58 59 60 |
# File 'lib/configliere/crypter.rb', line 53 def self.decrypt enc_ciphertext, encrypt_pass, ={} iv_and_ciphertext = Base64.decode64(enc_ciphertext) 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
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/configliere/crypter.rb', line 36 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 Base64.encode64(combine_iv_and_ciphertext(iv, ciphertext)) end |