Class: Desviar::EncryptedItem::Encryptor::Version2Encryptor

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

Instance Attribute Summary

Attributes inherited from Version1Encryptor

#key, #plaintext_data

Instance Method Summary collapse

Methods inherited from Version1Encryptor

#encrypted_data, #initialize, #iv, #openssl_encryptor, #serialized_data

Constructor Details

This class inherits a constructor from Desviar::EncryptedItem::Encryptor::Version1Encryptor

Instance Method Details

#for_encrypted_itemObject

Returns a wrapped and encrypted version of plaintext_data suitable for using as the value in an encrypted data bag item.



160
161
162
163
164
165
166
167
168
# File 'lib/encrypt.rb', line 160

def for_encrypted_item
  {
    "encrypted_data" => encrypted_data,
    "hmac" => hmac,
    "iv" => Base64.encode64(iv),
    "version" => 2,
    "cipher" => ALGORITHM
  }
end

#hmacObject

Generates an HMAC-SHA2-256 of the encrypted data (encrypt-then-mac)



171
172
173
174
175
176
177
# File 'lib/encrypt.rb', line 171

def hmac
  @hmac ||= begin
    digest = OpenSSL::Digest::Digest.new("sha256")
    raw_hmac = OpenSSL::HMAC.digest(digest, key, encrypted_data)
    Base64.encode64(raw_hmac)
  end
end