1

Looking at the description below, it doesn't looks like the AES-GCM mode in Crypto. Cipher library can take in AAD data. Do we need to handle it separately for using this? Can advise if my understanding is correct. How to achieve the AES-GCM encryption with using this library if I have the AAD portion in my content need to be take care?

enter image description here

4
  • 1
    The AAD are generally passed in PyCryptodome with update(), s. also this example.
    – Topaco
    Oct 16, 2020 at 8:05
  • PyCrypto is abandoned, use alternatives like pyca/cryptography cryptography.io/en/latest/hazmat/primitives/aead/… Oct 16, 2020 at 8:24
  • @frost-nzcr4 - OP uses PyCryptodome and not legacy PyCrypto, at least according to the posted documentation excerpt. So there's actually no reason to recommend a change (especially since library recommendations are off-topic on SO).
    – Topaco
    Oct 16, 2020 at 8:40
  • Ok, my fault, but at least question should provide proper library name. And second, recommendations in answer with the actual libraries that can help with encryption isn't the same as question asking recommendations to ignite the flamewar. Oct 16, 2020 at 9:27

1 Answer 1

1

As Topaco said in comment, use update(). For example:

from Crypto.Cipher import AES
nonce = bytes(12)
data = bytes(0)
ad = bytes(16)
cipher = AES.new(key, AES.MODE_GCM, nonce=nonce)
cipher.update(ad)
ciphertext, tag = cipher.encrypt_and_digest(data)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.