def encrypt_str(self, content, key, salt, salt_explicit):
# return the encrypted content prepended with the
# gcm tag and salt_explicit
cipher = Cipher(algorithms.AES(key),
modes.GCM(initialization_vector=self._bulid_iv(salt, salt_explicit)),
backend=default_backend()
).encryptor()
ciphertext = cipher.update(content) + cipher.finalize()
return struct.pack('!q16s', salt_explicit, cipher.tag) + ciphertext
评论列表
文章目录