【发布时间】:2017-06-16 13:02:34
【问题描述】:
在我的后端,他们使用带有 16 字节密钥的 AES 算法和这段代码创建了加密消息
密钥:h7Ui63Mzqj61G87j
public static String encrypt(String data, byte[] secretKey) throws Exception {
Key key = generateKey(secretKey);
Cipher c = Cipher.getInstance(ALGORITHM);
c.init(Cipher.ENCRYPT_MODE, key);
byte[] encVal = c.doFinal(data.getBytes());
String encryptedValue = new BASE64Encoder().encode(encVal);
if (logger.isDebugEnabled()) {
logger.debug(String.format("DataToEncrypt: %s, encryptedValue: %s", data, encryptedValue));
}
return encryptedValue;
}
但我无法使用 AES 算法使用相同的密钥解密消息。
【问题讨论】:
-
您的密钥长度为 16 个字符。怎么转换成 32 字节?
-
好的,现在我们有 16 个字符 vs 16 个字节。如何从字符转换为字节?
-
请展示您目前拥有的 Objective-C 代码。并告诉我们“我无法解密消息”是什么意思。它不会编译吗?它会崩溃吗?它会产生错误的输出吗?什么输入,什么是预期输出,什么是有效输出?
-
从服务器端,他们使用密钥加密消息,并且在 Objective-C 代码中无法使用相同的密钥解密消息
-
得到空值。
标签: ios objective-c encryption cryptography aes