MCPcopy Index your code
hub / github.com/authlib/authlib / encrypt

Method encrypt

authlib/jose/drafts/_jwe_enc_cryptography.py:25–37  ·  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

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

Callers

nothing calls this directly

Calls 1

check_ivMethod · 0.80

Tested by

no test coverage detected