def decrypt!(private_key_or_secret, algorithms = nil, encryption_methods = nil)
raise UnexpectedAlgorithm.new('Unexpected alg header') unless algorithms.blank? || Array(algorithms).include?(alg)
raise UnexpectedAlgorithm.new('Unexpected enc header') unless encryption_methods.blank? || Array(encryption_methods).include?(enc)
self.private_key_or_secret = with_jwk_support private_key_or_secret
cipher.decrypt
self.content_encryption_key = decrypt_content_encryption_key
self.mac_key, self.encryption_key = derive_encryption_and_mac_keys
cipher.key = encryption_key
cipher.iv = iv
if gcm?
raise DecryptionFailed.new('Invalid authentication tag') if authentication_tag.length < 16
cipher.auth_tag = authentication_tag
cipher.auth_data = auth_data
end
self.plain_text = cipher.update(cipher_text) + cipher.final
verify_cbc_authentication_tag! if cbc?
self
end