【发布时间】:2014-07-14 21:24:12
【问题描述】:
我在我的 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 或 bouncy castle 中,无法获得 openssl 返回的确切身份验证标签,您能帮我解决这个问题吗?谢谢
【问题讨论】:
-
你能澄清一下确切的问题吗?您需要配置标签长度还是要从密码中获取标签值?
-
感谢 Oleg Estekhin。我正在尝试从密码中获取与 openssl 生成的标签相同的标签值。
标签: java android ios encryption aes-gcm