title: AES GCM implementation with authentication Tag in Java
body: <p>I'm using AES GCM authentication in my android project and it works fine. But getting some issues with authentication tag when it compare with openssl API generate tag. Please find the java code below:</p>
  
  <pre><code>SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
  byte[] iv = generateRandomIV();
  IvParameterSpec ivspec = new IvParameterSpec(iv);
  Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
  cipher.init(Cipher.ENCRYPT_MODE, skeySpec, ivspec);
  int outputLength = cipher.getOutputSize(data.length); // Prepare output buffer
  byte[] output = new byte[outputLength];
  int outputOffset = cipher.update(data, 0, data.length, output, 0);// Produce cipher text
  outputOffset += cipher.doFinal(output, outputOffset);
  </code></pre>
  
  <p>I am using openssl for the same in iOS and generating authentication tag using below code</p>
  
  <pre><code>NSMutableData* tag = [NSMutableData dataWithLength:tagSize];
  EVP_CIPHER_CTX_ctrl(&amp;ctx, EVP_CTRL_GCM_GET_TAG, [tag length], [tag mutableBytes])
  </code></pre>
  
  <p>In java or bouncy castle, not able to get the exact authentication tag which openssl return and can you help me to resolve this issue. Thanks</p>