问题
Currently the encryption mode supported with AES 256 is CBC
. But I want to use AES 256 encryption
with GCM
mode along with PKCS5Padding / PKCS7Padding
.
Do let me know how it can be done ?
回答1:
Common Crypto does not support GCM. But there is an implementation of AES GCM in the Security.framework, and you can add your own header file to use it. However associated data (AEAD) does not work.
From SO Answer by soyer:
CCCryptorStatus CCCryptorGCM(
CCOperation op, // kCCEncrypt, kCCDecrypt
CCAlgorithm kCCAlgorithmAES,
const void *key, size_t keyLength,
const void *iv, size_t ivLen,
const void *aData, size_t aDataLen, // does not work
const void *dataIn, size_t dataInLength,
void *dataOut,
const void *tag, size_t *tagLength);
There is an implemntation AES GCM on github that seems reasonable albiet slow in comparison to Common Crypto. Use at your own risk.
来源:https://stackoverflow.com/questions/40213648/support-of-aes-256-with-gcm-not-possible-in-ios