Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

swift - How to encrypt using AES GCM on iOS?

I need to encrypt/decrypt some data using AES encryption on GCM mode, but apparently this can't be done with the CommonCrypto API. This has been asked previously here, but the accepted answer is not what I'm looking for, since I need to use this specific algorithm.

Any ideas? Should I use OpenSSL? Because I've heard that there are some bugs when using it in iOS.

I'm looking for an answer in Swift, but Objective-C would be fine as well.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is some GCM crypt functions in the CommonCryptorSPI.h, they are not public yet. But you can use them if you add them to the bridging header.

#include <CommonCrypto/CommonCryptor.h>
CCCryptorStatus CCCryptorGCM(
CCOperation     op,             /* kCCEncrypt, kCCDecrypt */
CCAlgorithm     alg,
const void      *key,           /* raw key material */
size_t          keyLength,  
const void      *iv,
size_t          ivLen,
const void      *aData,
size_t          aDataLen,
const void      *dataIn,
size_t          dataInLength,
void            *dataOut,
const void      *tag,
size_t          *tagLength);

Or you can try the SwCrypt library.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...