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

Method encrypt

authlib/jose/drafts/_jwe_enc_cryptography.py:24–36  ·  view source on GitHub ↗

Content Encryption with AEAD_CHACHA20_POLY1305. :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, tag)

(self, msg, aad, iv, key)

Source from the content-addressed store, hash-verified

22 self.CEK_SIZE = key_size
23
24 def encrypt(self, msg, aad, iv, key):
25 """Content Encryption with AEAD_CHACHA20_POLY1305.
26
27 :param msg: text to be encrypt in bytes
28 :param aad: additional authenticated data in bytes
29 :param iv: initialization vector in bytes
30 :param key: encrypted key in bytes
31 :return: (ciphertext, tag)
32 """
33 self.check_iv(iv)
34 chacha = ChaCha20Poly1305(key)
35 ciphertext = chacha.encrypt(iv, msg, aad)
36 return ciphertext[:-16], ciphertext[-16:]
37
38 def decrypt(self, ciphertext, aad, iv, tag, key):
39 """Content Decryption with AEAD_CHACHA20_POLY1305.

Callers

nothing calls this directly

Calls 1

check_ivMethod · 0.80

Tested by

no test coverage detected