Class: SyrupPay::Jwa::A128CbcHmac256Encryption

Inherits:
ContentEncryption show all
Includes:
ActiveSupport::SecurityUtils
Defined in:
lib/jose/jwa/enc/aes128_hmac256_encryption.rb

Defined Under Namespace

Classes: InvalidVerifyError

Instance Attribute Summary

Attributes inherited from ContentEncryption

#iv_length, #key_length

Instance Method Summary collapse

Methods inherited from ContentEncryption

#content_encryption_generator, #generate_random_iv

Methods included from RandomKeyGen

#randomKey

Constructor Details

#initializeA128CbcHmac256Encryption

Returns a new instance of A128CbcHmac256Encryption.



14
15
16
# File 'lib/jose/jwa/enc/aes128_hmac256_encryption.rb', line 14

def initialize
  super 32, 16
end

Instance Method Details

#encrypt_and_sign(cek, iv, payload, aad) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/jose/jwa/enc/aes128_hmac256_encryption.rb', line 18

def encrypt_and_sign(cek, iv, payload, aad)
  iv = !iv.nil? ? iv : generate_random_iv
  hmac_key, enc_key = split_key(cek)

  cipher_text = encryption(enc_key, iv, payload)
  at = sign(hmac_key, iv, cipher_text, aad)

  [cipher_text, at, iv]
end

#verify_and_decrypt(cek, iv, cipher_text, aad, expected) ⇒ Object



28
29
30
31
32
33
# File 'lib/jose/jwa/enc/aes128_hmac256_encryption.rb', line 28

def verify_and_decrypt(cek, iv, cipher_text, aad, expected)
  hmac_key, enc_key = split_key(cek)

  verify_authentication_tag!(hmac_key, iv, cipher_text, aad, expected)
  decryption(enc_key, iv, cipher_text)
end