iOS 真的能支持 AES 256 吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9617190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:13:16  来源:igfitidea点击:

Can iOS really support AES 256?

iphoneobjective-ciosxcodesecurity

提问by Howard

I have read the header of CommonCryptor.h, and only I can find kCCAlgorithmAES128

我已经阅读了 的标题CommonCryptor.h,只有我能找到kCCAlgorithmAES128

But there are a few answer in SO stating it can, e.g.

但是在SO中有一些答案说明它可以,例如

AES Encryption for an NSString on the iPhone

iPhone 上 NSString 的 AES 加密

Anyone can answer?

任何人都可以回答吗?

回答by DarkDust

You can always use OpenSSL on iPhone, and that does support AES 256.

您始终可以在 iPhone 上使用 OpenSSL,而且它确实支持 AES 256。

That being said, kCCAlgorithmAES128means a blocklength of 128, not key length. According to this example code(found in this answer) you simply need to use kCCKeySizeAES256for the keyLengthparameter to get support for 256 bit keys.

话虽如此,这kCCAlgorithmAES128意味着长度为 128,而不是密钥长度。根据此示例代码(在此答案中找到),您只需使用kCCKeySizeAES256keyLength参数即可获得对 256 位密钥的支持。

回答by dom

Recently I discovered a category of NSData(also NSString) which implements AES en-/decryption. Maybe this is helpful to crypt any kind of data:

最近我发现了一类NSData(也NSString)实现了 AES 加密/解密。也许这有助于加密任何类型的数据:

Adding methods to NSData and NSString using categories to provide AES256 encryption on iOS

使用类别向 NSData 和 NSString 添加方法以在 iOS 上提供 AES256 加密

But it seems to have an implementation issue, which makes it incompatible with openSSL.

但它似乎有一个实现问题,这使得它与 openSSL 不兼容。

--

——

Another useful like might be Properly encrypting with AES with CommonCrypto. To support 256 bit keys just change the kCCKeySizeAES128to 256.

另一个有用的方法可能是使用 CommonCrypto 使用 AES 正确加密。要支持 256 位密钥,只需将 更改kCCKeySizeAES128为 256。

--

——

Last but not least this tread looks promising: Decode OpenSSL AES256 string in iOS

最后但并非最不重要的一点是:在 iOS 中解码 OpenSSL AES256 字符串

回答by Ankit Srivastava

If you goto http://www.opensource.apple.com/source/CommonCrypto/CommonCrypto-36064/CommonCrypto/CommonCryptor.hand search AES256 on the page you will find the key size as 256 ,192,128 so yes it does support AES256 encryption.

如果您转到http://www.opensource.apple.com/source/CommonCrypto/CommonCrypto-36064/CommonCrypto/CommonCryptor.h并在页面上搜索 AES256,您会发现密钥大小为 256 ,192,128 所以它确实支持 AES256加密。