I am pretty new to cryptography and have a sample of GCM mode of operation for AES.
PFB the code
Cipher c = Cipher.getInstance ("AES/GCM/NoPadding");
final int blockSize = 96;//c.getBlockSize();
final byte[] ivData = new byte[blockSize];
System.out.println("IV :- "+new String(ivData) );
final SecureRandom rnd = SecureRandom.getInstance("SHA1PRNG");
rnd.nextBytes(ivData);
System.out.println("IV :- "+new String(ivData) );
/**
*
*/
GCMParameterSpec params = new GCMParameterSpec(blockSize , ivData);
SecureRandom sr = new SecureRandom();
byte[] aesKey = MessageDigest.getInstance("MD5").digest(
"som3C0o7p@s5".getBytes());
byte[] ciphertext;
byte[] head = "Header information".getBytes();
byte[] data = "Data to encrypt".getBytes();
sr.nextBytes(aesKey);
SecretKeySpec sks = new SecretKeySpec(aesKey, "AES");
c.init(Cipher.ENCRYPT_MODE, sks, params);
c.updateAAD(head);
ciphertext = c.doFinal(data);
System.out.println("done "+ new String(ciphertext));
c.init(Cipher.DECRYPT_MODE, sks, params);
c.updateAAD(head);
ciphertext = c.doFinal(ciphertext);
System.out.println("done "+ new String(ciphertext));
But I need to do Authentication using GMAC. How do I do authentication using GMAC without encrypting/decrypting? Any pointers or suggestions will be very helpful.
c.doFinal(data);
? $\endgroup$