简体   繁体   English

AES数据加密和解密

[英]AES Encryption and Decryption of data

I am developing an iOS app in which: I am calling a Java web service. 我正在开发一个iOS应用程序,其中:我正在调用Java Web服务。

The service sends me the following data : 该服务向我发送以下数据:

  1. Salt value (Base64 encoded) 盐值(Base64编码)
  2. Base64 encoded key Base64编码密钥
  3. Encrypted data 加密数据

Now I need to decode this key and use it for the decryption of the same data. 现在,我需要解码此密钥,并将其用于解密相同的数据。

The problem with me is when I try to decode the key I get nil NSString . 我的问题是,当我尝试解码密钥时,得到nil NSString

Here by is the code that I have been trying : 这是我一直在尝试的代码:

NSData *cipherKeyData = [[NSData alloc] initWithBase64EncodedString:@"W0JAM2IwMDVhYmM=" options:NSUTF8StringEncoding];
NSString *strKey = [[NSString alloc] initWithData:cipherKeyData encoding:NSUTF8StringEncoding];

Hence, I am not able to decrypt the data. 因此,我无法解密数据。 Can anyone please help me out with this issue. 谁能帮我解决这个问题。

First strKey is a string: "[B@3b005abc", I do not get nil . 第一个strKey是一个字符串:“ [B @ 3b005abc”,我没有得到nil

Keys are generally data, cipherKeyData is the key. 密钥通常是数据, cipherKeyData是密钥。 The reason the key was supplied in Base64 is because the actual key is data, not a string. 之所以在Base64中提供密钥,是因为实际的密钥是数据,而不是字符串。 No further conversion to a string is necessary. 无需进一步转换为字符串。 The key parameter to the Common Crypto encryption functions are data, not an NSString . Common Crypto加密功能的关键参数是数据,而不是NSString

Not all data can be converted to a string, there are data bytes and for UTF-* sequences that are illegal code points. 并非所有数据都可以转换为字符串,而是有数据字节,对于UTF- *序列,它们是非法代码点。 In the case in the question the data will convert to the string "[B@3b005abc". 在问题的情况下,数据将转换为字符串“ [B @ 3b005abc””。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM