Class: Desviar::EncryptedItem::Decryptor::Version2Decryptor

Inherits:
Version1Decryptor show all
Defined in:
lib/encrypt.rb

Instance Attribute Summary

Attributes inherited from Version1Decryptor

#encrypted_data, #key

Instance Method Summary collapse

Methods inherited from Version1Decryptor

#assert_valid_cipher!, #encrypted_bytes, #for_decrypted_item, #initialize, #iv, #openssl_decryptor

Constructor Details

This class inherits a constructor from Desviar::EncryptedItem::Decryptor::Version1Decryptor

Instance Method Details

#decrypted_dataObject



287
288
289
290
# File 'lib/encrypt.rb', line 287

def decrypted_data
  validate_hmac! unless @decrypted_data
  super
end

#validate_hmac!Object



292
293
294
295
296
297
298
299
300
301
# File 'lib/encrypt.rb', line 292

def validate_hmac!
  digest = OpenSSL::Digest::Digest.new("sha256")
  raw_hmac = OpenSSL::HMAC.digest(digest, key, @encrypted_data["encrypted_data"])

  if candidate_hmac_matches?(raw_hmac)
    true
  else
    raise DecryptionFailure, "Error decrypting data bag value: invalid hmac. Most likely the provided key is incorrect"
  end
end