如何在iOS上使用AES GCM加密? [英] How to encrypt using AES GCM on iOS?

查看:2666
本文介绍了如何在iOS上使用AES GCM加密?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在GCM模式下使用AES加密来加密/解密一些数据,但显然这不能通过CommonCrypto API完成。之前已询问过此处 ,但接受的答案不是我正在寻找,因为我需要使用这个特定的算法。

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.

有什么想法吗?我应该使用OpenSSL吗?因为我听说在iOS中使用它有一些错误。

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

我在Swift寻找答案,但Objective-C也不错。

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

推荐答案

CommonCryptorSPI.h ,它们尚未公开。
但是你可以使用它们,如果你将它们添加到桥接头。

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);

或者您可以尝试 SwCrypt 库。

这篇关于如何在iOS上使用AES GCM加密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆