Class: Desviar::EncryptedItem::Decryptor::Version0Decryptor
- Inherits:
-
Object
- Object
- Desviar::EncryptedItem::Decryptor::Version0Decryptor
- Defined in:
- lib/encrypt.rb
Instance Attribute Summary collapse
-
#encrypted_data ⇒ Object
readonly
Returns the value of attribute encrypted_data.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #decrypted_data ⇒ Object
- #encrypted_bytes ⇒ Object
- #for_decrypted_item ⇒ Object
-
#initialize(encrypted_data, key) ⇒ Version0Decryptor
constructor
A new instance of Version0Decryptor.
- #openssl_decryptor ⇒ Object
Constructor Details
#initialize(encrypted_data, key) ⇒ Version0Decryptor
Returns a new instance of Version0Decryptor.
320 321 322 323 |
# File 'lib/encrypt.rb', line 320 def initialize(encrypted_data, key) @encrypted_data = encrypted_data @key = key end |
Instance Attribute Details
#encrypted_data ⇒ Object (readonly)
Returns the value of attribute encrypted_data.
317 318 319 |
# File 'lib/encrypt.rb', line 317 def encrypted_data @encrypted_data end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
318 319 320 |
# File 'lib/encrypt.rb', line 318 def key @key end |
Instance Method Details
#decrypted_data ⇒ Object
329 330 331 332 333 334 335 336 |
# File 'lib/encrypt.rb', line 329 def decrypted_data @decrypted_data ||= begin plaintext = openssl_decryptor.update(encrypted_bytes) plaintext << openssl_decryptor.final rescue OpenSSL::Cipher::CipherError => e raise DecryptionFailure, "Error decrypting data bag value: '#{e.}'. Most likely the provided key is incorrect" end end |
#encrypted_bytes ⇒ Object
338 339 340 |
# File 'lib/encrypt.rb', line 338 def encrypted_bytes Base64.decode64(@encrypted_data) end |
#for_decrypted_item ⇒ Object
325 326 327 |
# File 'lib/encrypt.rb', line 325 def for_decrypted_item YAML.load(decrypted_data) end |
#openssl_decryptor ⇒ Object
342 343 344 345 346 347 348 349 |
# File 'lib/encrypt.rb', line 342 def openssl_decryptor @openssl_decryptor ||= begin d = OpenSSL::Cipher::Cipher.new(ALGORITHM) d.decrypt d.pkcs5_keyivgen(key) d end end |