Class: Desviar::EncryptedItem::Decryptor::Version0Decryptor

Inherits:
Object
  • Object
show all
Defined in:
lib/encrypt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_dataObject (readonly)

Returns the value of attribute encrypted_data.



317
318
319
# File 'lib/encrypt.rb', line 317

def encrypted_data
  @encrypted_data
end

#keyObject (readonly)

Returns the value of attribute key.



318
319
320
# File 'lib/encrypt.rb', line 318

def key
  @key
end

Instance Method Details

#decrypted_dataObject



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.message}'. Most likely the provided key is incorrect"
  end
end

#encrypted_bytesObject



338
339
340
# File 'lib/encrypt.rb', line 338

def encrypted_bytes
  Base64.decode64(@encrypted_data)
end

#for_decrypted_itemObject



325
326
327
# File 'lib/encrypt.rb', line 325

def for_decrypted_item
  YAML.load(decrypted_data)
end

#openssl_decryptorObject



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