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

Method encrypt

authlib/jose/rfc7518/jwe_encs.py:105–119  ·  view source on GitHub ↗

Key Encryption with AES GCM. :param msg: text to be encrypt in bytes :param aad: additional authenticated data in bytes :param iv: initialization vector in bytes :param key: encrypted key in bytes :return: (ciphertext, iv, tag)

(self, msg, aad, iv, key)

Source from the content-addressed store, hash-verified

103 self.CEK_SIZE = key_size
104
105 def encrypt(self, msg, aad, iv, key):
106 """Key Encryption with AES GCM.
107
108 :param msg: text to be encrypt in bytes
109 :param aad: additional authenticated data in bytes
110 :param iv: initialization vector in bytes
111 :param key: encrypted key in bytes
112 :return: (ciphertext, iv, tag)
113 """
114 self.check_iv(iv)
115 cipher = Cipher(AES(key), GCM(iv), backend=default_backend())
116 enc = cipher.encryptor()
117 enc.authenticate_additional_data(aad)
118 ciphertext = enc.update(msg) + enc.finalize()
119 return ciphertext, enc.tag
120
121 def decrypt(self, ciphertext, aad, iv, tag, key):
122 """Key Decryption with AES GCM.

Callers 1

wrapMethod · 0.45

Calls 1

check_ivMethod · 0.80

Tested by

no test coverage detected