在IOS中使用AES加密

在IOS中使用AES加密,ios,json,encryption,base64,aes,Ios,Json,Encryption,Base64,Aes,我在加密时遇到问题 服务器正在发送json数据,该数据经过aes256加密,然后进行base64编码。 而在ios客户端,我能够获得响应并使用base64对其进行解码。 AES256解密在某些库(CommonCryptor.h周围的第三方或包装器)上工作,而在另一个库中不工作。 解密工作时,解析不工作 以下是包装器库和相应的代码 加密机 () 我在解密时遇到以下错误 EncryptedParsing[4402:70b] error2 - Error Domain=net.robnapier.RN

我在加密时遇到问题

服务器正在发送json数据,该数据经过aes256加密,然后进行base64编码。 而在ios客户端,我能够获得响应并使用base64对其进行解码。 AES256解密在某些库(CommonCryptor.h周围的第三方或包装器)上工作,而在另一个库中不工作。 解密工作时,解析不工作

以下是包装器库和相应的代码

加密机 ()

我在解密时遇到以下错误

EncryptedParsing[4402:70b] error2 - Error Domain=net.robnapier.RNCryptManager Code=2 "Unknown header" UserInfo=0x8c6bd60 {NSLocalizedDescription=Unknown header}
CCrypto ()

这里我得到的是解密后的数据,但在解析时,它给出了以下错误

EncryptedParsing[4469:70b] error1 - Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x8a51520 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
EncryptedParsing[4646:70b] error - Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x8a710c0 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
NSData+AES256 ()

我得到了解密数据,在解析时我得到了以下错误

EncryptedParsing[4469:70b] error1 - Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x8a51520 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
EncryptedParsing[4646:70b] error - Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x8a710c0 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
除此之外,我还使用了CocoaSecurity() 但它不起作用

我正在使用NSData+Base64()进行Base64解码

顺便说一下,服务器端没有问题(我们测试了它)


我想知道我所犯的错误。或者有没有其他方法来实现这一点

尝试用针织品代替NSJSONReadingMutableLeaf。

没有通用的标准方法来编码AES加密数据。您需要双方就如何编码所需的各种元数据达成一致

RNCryptor无法解密,因为它希望数据位于

CCCrypto和AES256DecryptWithKey对密钥的解释可能与您的预期不同。这两种方法都不能验证您传递的密钥是否正确,因此您可能会收到垃圾。如果是这样的话,我希望对于某些消息,您会得到垃圾回复,而对于其他消息,您不会得到任何回复或错误

如果您需要跨平台解决方案,可以使用多种语言实现。如果需要符合服务器格式(从代码外观来看,这可能不是安全加密),则需要提供服务器代码以确定正确的客户端代码

EncryptedParsing[4646:70b] error - Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x8a710c0 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}