Key Encryption with AES GCM. :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, iv, tag)
(self, msg, aad, iv, key)
| 105 | self.CEK_SIZE = key_size |
| 106 | |
| 107 | def encrypt(self, msg, aad, iv, key): |
| 108 | """Key Encryption with AES GCM. |
| 109 | |
| 110 | :param msg: text to be encrypt in bytes |
| 111 | :param aad: additional authenticated data in bytes |
| 112 | :param iv: initialization vector in bytes |
| 113 | :param key: encrypted key in bytes |
| 114 | :return: (ciphertext, iv, tag) |
| 115 | """ |
| 116 | self.check_iv(iv) |
| 117 | cipher = Cipher(AES(key), GCM(iv), backend=default_backend()) |
| 118 | enc = cipher.encryptor() |
| 119 | enc.authenticate_additional_data(aad) |
| 120 | ciphertext = enc.update(msg) + enc.finalize() |
| 121 | return ciphertext, enc.tag |
| 122 | |
| 123 | def decrypt(self, ciphertext, aad, iv, tag, key): |
| 124 | """Key Decryption with AES GCM. |