I use AES GCM authentication in my Android project and it works great. But there is a problem with the authentication tag when it compares with the openssl API tag. Please find the java code below:
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);
byte[] output = new byte[outputLength];
int outputOffset = cipher.update(data, 0, data.length, output, 0);
outputOffset += cipher.doFinal(output, outputOffset);
I use openssl for the same in iOS and generate an authentication tag using the code below
NSMutableData* tag = [NSMutableData dataWithLength:tagSize];
EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_GCM_GET_TAG, [tag length], [tag mutableBytes])
In java or bouncy castle, unable to get the exact authentication tag that openssl returns, and you can help me solve this problem. Thanks
source
share