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)
| 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. |