MCPcopy
hub / github.com/authlib/authlib / encrypt

Method encrypt

authlib/jose/drafts/_jwe_enc_cryptodome.py:25–38  ·  view source on GitHub ↗

Content Encryption with AEAD_XCHACHA20_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_XCHACHA20_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 = Cryptodome_ChaCha20_Poly1305.new(key=key, nonce=iv)
36 chacha.update(aad)
37 ciphertext, tag = chacha.encrypt_and_digest(msg)
38 return ciphertext, tag
39
40 def decrypt(self, ciphertext, aad, iv, tag, key):
41 """Content Decryption with AEAD_XCHACHA20_POLY1305.

Callers

nothing calls this directly

Calls 1

check_ivMethod · 0.80

Tested by

no test coverage detected