// generate a unique AES key and (later) encrypt it with the public RSA key of the merchant
NSMutableData *key = [NSMutableData dataWithLength:kCCKeySizeAES256];
SecRandomCopyBytes(NULL, kCCKeySizeAES256, key.mutableBytes);
// generate a nonce
NSMutableData *iv = [NSMutableData dataWithLength:12];
SecRandomCopyBytes(NULL, 12, iv.mutableBytes);
NSData *cipherText = [TKAESCCMCryptor encrypt:data withKey:key iv:iv];
NSData *encryptedKey = [TKRSACryptor encrypt:key withKeyInHex:keyInHex];
或者使用 wrapper 类 TKCryptor
和它的方法
+ (NSString *)encrypt:(NSData *)data publicKeyInHex:(NSString *)keyInHex;
它们执行以下操作
""
)$
)$
)注意
tagLength = 8
ivLength = 12
L = 3
Exponent|Modulus
TKCryptor 可通过 CocoaPods 获得。要安装,只需将以下行添加到 Podfile 中
pod "TKCryptor", :git => "https://github.com/xslim/TKCryptor.git"
TKCryptor 可在 MIT 许可下获得。有关更多信息,请参阅 LICENSE 文件。