MCPcopy Create free account
hub / github.com/authlib/authlib / decrypt

Method decrypt

authlib/jose/rfc7518/jwe_encs.py:69–91  ·  view source on GitHub ↗

Key Decryption with AES AES_CBC_HMAC_SHA2. :param ciphertext: ciphertext in bytes :param aad: additional authenticated data in bytes :param iv: initialization vector in bytes :param tag: authentication tag in bytes :param key: encrypted key in bytes :

(self, ciphertext, aad, iv, tag, key)

Source from the content-addressed store, hash-verified

67 return ciphertext, tag
68
69 def decrypt(self, ciphertext, aad, iv, tag, key):
70 """Key Decryption with AES AES_CBC_HMAC_SHA2.
71
72 :param ciphertext: ciphertext in bytes
73 :param aad: additional authenticated data in bytes
74 :param iv: initialization vector in bytes
75 :param tag: authentication tag in bytes
76 :param key: encrypted key in bytes
77 :return: message
78 """
79 self.check_iv(iv)
80 hkey = key[: self.key_len]
81 dkey = key[self.key_len :]
82
83 _tag = self._hmac(ciphertext, aad, iv, hkey)
84 if not hmac.compare_digest(_tag, tag):
85 raise InvalidTag()
86
87 cipher = Cipher(AES(dkey), CBC(iv), backend=default_backend())
88 d = cipher.decryptor()
89 data = d.update(ciphertext) + d.finalize()
90 unpad = PKCS7(AES.block_size).unpadder()
91 return unpad.update(data) + unpad.finalize()
92
93
94class GCMEncAlgorithm(JWEEncAlgorithm):

Callers

nothing calls this directly

Calls 2

_hmacMethod · 0.95
check_ivMethod · 0.80

Tested by

no test coverage detected