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

Method encrypt

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

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

Callers

nothing calls this directly

Calls 1

check_ivMethod · 0.80

Tested by

no test coverage detected