Class: AesEncryption
- Inherits:
-
Object
- Object
- AesEncryption
- Defined in:
- lib/trustcaptcha/aes_encryption.rb
Constant Summary collapse
- STANDARD_BLOCK_SIZE =
16
Class Method Summary collapse
- .decrypt(key, encrypted_data) ⇒ Object
- .decrypt_to_string(key, encrypted_text) ⇒ Object
- .to_aes_secret_key(key_string) ⇒ Object
Class Method Details
.decrypt(key, encrypted_data) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/trustcaptcha/aes_encryption.rb', line 16 def self.decrypt(key, encrypted_data) iv = encrypted_data[0, STANDARD_BLOCK_SIZE] cipher_text = encrypted_data[STANDARD_BLOCK_SIZE..-1] decipher = OpenSSL::Cipher::AES256.new(:CBC) decipher.decrypt decipher.key = key decipher.iv = iv decrypted = decipher.update(cipher_text) + decipher.final decrypted.force_encoding('UTF-8') end |
.decrypt_to_string(key, encrypted_text) ⇒ Object
11 12 13 14 |
# File 'lib/trustcaptcha/aes_encryption.rb', line 11 def self.decrypt_to_string(key, encrypted_text) decoded = Base64.decode64(encrypted_text) decrypt(key, decoded) end |
.to_aes_secret_key(key_string) ⇒ Object
7 8 9 |
# File 'lib/trustcaptcha/aes_encryption.rb', line 7 def self.to_aes_secret_key(key_string) Base64.decode64(key_string) end |