For AES128 using CCCrypt() can the key be longer than 128 bits?

房东的猫 提交于 2019-12-05 10:49:12

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.

poupou

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!