我在我的 android 项目中使用 AES GCM 身份验证,它工作正常。但是与 openssl API 生成标签相比,身份验证标签出现了一些问题。请在下面找到java代码:
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);
我在 iOS 中使用相同的 openssl 并使用下面的代码生成身份验证标签
NSMutableData* tag = [NSMutableData dataWithLength:tagSize];
EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_GCM_GET_TAG, [tag length], [tag mutableBytes])
在 java 或充气城堡中,无法获得 openssl 返回的确切身份验证标签,您能帮我解决这个问题吗?谢谢