对于使用 CCCrypt() 的 AES128,密钥可以长于 128 位吗?
我正在使用 CCCrypt
方法。
我可以使用比 128 位更长的密钥吗?可以任意长吗?或者也许是 128 的倍数?
如果是这样我该怎么做?
我认为这不可能,但我发现了这段文字: 这里
一些算法(例如 AES 和 RSA)允许使用不同长度的密钥,但其他算法是固定的,例如 DES 和 3DES。使用较长密钥的加密通常意味着对消息恢复的更强抵抗力。与往常一样,安全性和时间之间需要权衡,因此请适当选择密钥长度。
AES 如何允许不同的长度,它是否忽略高于 128 的位?
我正在为此抓狂。
I am using the CCCrypt
method.
Can I use a longer key than than 128bit? Can it be arbitrarily long? Or perhaps multiples of 128?
If so how would I do this?
I didn't think this woas possible but I found this text: here
Some algorithms such as AES and RSA allow for keys of different lengths, but others are fixed, such as DES and 3DES. Encryption using a longer key generally implies a stronger resistance to message recovery. As usual, there is a trade off between security and time, so choose the key length appropriately.
How does AES allow for different lengths, does it ignore the bits higher than 128?
I'm pulling my hair out over this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AES(高级加密标准)实际上是三种相关分组密码算法(或成对的分组密码算法)的集合。算法(如果单独计算加密和解密)。它们都工作在 128 位块(16 字节)上。
最常用的是 AES-128,它采用 128 位密钥(即 16 字节)。 AES-192 采用 192 位密钥(24 字节),AES-256 采用 256 位密钥(32 字节)。
这三种算法的工作方式类似,但仍然不同(并且较长密钥的算法需要更长的时间,因为它们进行更多“轮次”的内部混淆操作,因此密钥的所有位可以以某种方式影响密文的所有位)。因此,所有这些算法的所有这些密钥的加密和解密方式都不同(即,没有 AES-256 密钥与 AES-128 密钥具有相同的功能)。
也就是说,不幸的是,我不知道 CommonCrypto 库是否支持 AES 的所有变体,如果是(我想),如何选择正确的。
AES (the Advanced Encryption Standard) is actually a collection of three related block cipher algorithms (or pairs of algorithms, if one counts encryption and decryption individually). They all work on 128-bit blocks (16 bytes).
The most commonly used one is AES-128, which takes a 128-bit key (i.e. 16 bytes). AES-192 takes a 192-bit key (24 bytes), AES-256 takes a 256-bit key (32 bytes).
These three algorithms work in similar, but still different ways (and the ones for longer keys take a bit longer, since they do more "rounds" of the internal confusion operation, so all bits of the keys can somehow influence all bits of the ciphertext). Thus all these keys for all these algorithms encrypt and decrypt differently (i.e. there is no AES-256 key which does the same thing as an AES-128 key).
That said, I unfortunately have no idea if the CommonCrypto library supports all variants of AES, and if yes (what I suppose), how to select the right one.
保罗的解释非常好!并且比 Apple 关于该主题的文档要好得多;-)
现在要将这些知识放在 iOS 上下文中......您需要知道 cccrypt (如其命名手册页)通常被命名为CommonCrypto(可以方便您的搜索)位于网站其他位置。
然而,除非您意识到这部分是开源软件并且确实缺乏文档,否则您不会发现太多内容。
但是一旦找到这个,您就可以搜索源代码来查找 CommonCrypto.h 并发现您可以使用的枚举,其中包括: kCCKeySizeAES128、kCCKeySizeAES192 和 kCCKeySizeAES256 - 因此是您可以使用 256 位密钥与 AES在 iOS 上。
Paulo explanation is excellent! and much better than Apple documentation on the subject ;-)
Now to put this knowledge in iOS context... you need to know that cccrypt (like its named in man pages) is often named CommonCrypto (which can facilitate your searches) elsewhere in the web site.
Yet you won't find much until you realize this part is open source software and really lacks documentation.
But once you find this you can search thru the source code to find CommonCrypto.h and discover the enums you can use, which includes: kCCKeySizeAES128, kCCKeySizeAES192 and kCCKeySizeAES256 - so YES you can use 256bits keys with AES on iOS.