AES加密和数据解密

时间:2021-12-13 14:35:40

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)
  2. 盐值(Base64编码)

  3. Base64 encoded key
  4. Base64编码密钥

  5. 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.

因此,我无法解密数据。任何人都可以帮我解决这个问题。

1 个解决方案

#1


0  

First strKey is a string: "[B@3b005abc", I do not get nil.

第一个strKey是一个字符串:“[B @ 3b005abc”,我没有得到。

Keys are generally data, cipherKeyData is the key. The reason the key was supplied in Base64 is because the actual key is data, not a string. No further conversion to a string is necessary. The key parameter to the Common Crypto encryption functions are data, not an NSString.

密钥通常是数据,cipherKeyData是密钥。在Base64中提供密钥的原因是因为实际密钥是数据,而不是字符串。不需要进一步转换为字符串。 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. In the case in the question the data will convert to the string "[B@3b005abc".

并非所有数据都可以转换为字符串,有数据字节,UTF- *序列是非法代码点。在问题的情况下,数据将转换为字符串“[B @ 3b005abc”。

#1


0  

First strKey is a string: "[B@3b005abc", I do not get nil.

第一个strKey是一个字符串:“[B @ 3b005abc”,我没有得到。

Keys are generally data, cipherKeyData is the key. The reason the key was supplied in Base64 is because the actual key is data, not a string. No further conversion to a string is necessary. The key parameter to the Common Crypto encryption functions are data, not an NSString.

密钥通常是数据,cipherKeyData是密钥。在Base64中提供密钥的原因是因为实际密钥是数据,而不是字符串。不需要进一步转换为字符串。 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. In the case in the question the data will convert to the string "[B@3b005abc".

并非所有数据都可以转换为字符串,有数据字节,UTF- *序列是非法代码点。在问题的情况下,数据将转换为字符串“[B @ 3b005abc”。