How can I get a 12-byte authentication tag in AES-GCM

0 votes
AES-GCM ensures both encryption and data integrity, generating an authentication tag. How do I correctly configure it to produce a 12-byte tag, and what are the implications of varying tag sizes?
Dec 5, 2024 in Cyber Security & Ethical Hacking by Anupam
• 9,050 points
44 views

1 answer to this question.

0 votes

To generate a 12-byte (96-bit) authentication tag using AES-GCM, you need to configure the GCM mode to output a tag of the desired length. Here’s how to achieve it:

Steps to Get a 12-Byte Authentication Tag

  1. Use a Library Supporting GCM
    Ensure the cryptographic library you use supports specifying the tag length. Examples include OpenSSL, PyCryptodome (Python), and JCE (Java).

  2. Specify the Tag Length
    When initializing the AES-GCM operation, set the tag length parameter to 12 bytes (96 bits). Here's how it works in common tools:

    • OpenSSL: Use the EVP_CIPHER_CTX_ctrl function to set the tag length.
    • PyCryptodome (Python): AES-GCM uses a default 16-byte tag but allows specifying a shorter tag when finalizing encryption.
    • JCE (Java): Use the GCMParameterSpec class and set the tLen parameter to 96 (bits).
  3. Encrypt Data
    Perform the encryption with AES-GCM, and it will produce a 12-byte tag alongside the ciphertext.

  4. Store or Transmit the Tag
    Save the tag securely along with the ciphertext, as it’s required for decryption and verification.

Example (Using PyCryptodome in Python)
from Cryptodome.Cipher import AES
from Cryptodome.Random import get_random_bytes

# Generate a key and data
key = get_random_bytes(16)
data = b"Secret message"
nonce = get_random_bytes(12)

# Encrypt with AES-GCM
cipher = AES.new(key, AES.MODE_GCM, nonce=nonce, mac_len=12)  # mac_len specifies tag length
ciphertext, tag = cipher.encrypt_and_digest(data)

print(f"Ciphertext: {ciphertext}")
print(f"Authentication Tag (12 bytes): {tag}")
answered Dec 5, 2024 by CaLLmeDaDDY
• 13,760 points

Related Questions In Cyber Security & Ethical Hacking

+1 vote
1 answer
0 votes
1 answer
0 votes
0 answers
+1 vote
1 answer

How do you decrypt a ROT13 encryption on the terminal itself?

Yes, it's possible to decrypt a ROT13 ...READ MORE

answered Oct 17, 2024 in Cyber Security & Ethical Hacking by CaLLmeDaDDY
• 13,760 points
174 views
+1 vote
1 answer

How does the LIMIT clause in SQL queries lead to injection attacks?

The LIMIT clause in SQL can indeed ...READ MORE

answered Oct 17, 2024 in Cyber Security & Ethical Hacking by CaLLmeDaDDY
• 13,760 points
342 views
+1 vote
1 answer

Is it safe to use string concatenation for dynamic SQL queries in Python with psycopg2?

The use of string concatenation while building ...READ MORE

answered Oct 17, 2024 in Cyber Security & Ethical Hacking by CaLLmeDaDDY
• 13,760 points
184 views
+1 vote
1 answer
+1 vote
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP