AES Key Wrap (RFC 3394) 和 AES Key Wrap with Padding (RFC 5649) 算法的 ObjC 实现。
CommonCrypto 已提供一些实现 RFC 3394 的函数
但它还没有提供任何实现带填充的包装的函数 (RFC 5649) ...
AesKeyWrap 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile
pod "AesKeyWrap"
#import <CommonCrypto/CommonCryptor.h>
#import "AKWAesKeyWrap.h"
u_char keyBytes[kCCKeySizeAES192] = {...};
NSData *keyEncryptionKey = [NSData dataWithBytes:keyBytes length:kCCKeySizeAES192];
// AES Key Wrap
u_char plainBytes[2 * sizeof(uint64_t)] = {...};
NSData *expectedPlainData = [NSData dataWithBytes:plainBytes length:sizeof(plainBytes)];
NSData *cipheredData = [AKWAesKeyWrap cipheredDataByWrappingPlainData:expectedPlainData
withKeyEncryptionKey:keyEncryptionKey
error:nil];
NSData *plainData = [AKWAesKeyWrap plainDataByUnwrappingCipheredData:cipheredData
withKeyEncryptionKey:keyEncryptionKey
error:nil];
XCTAssertEqualObjects(expectedPlainData, plainData);
// AES Key Wrap with Padding
u_char plainBytesWithPadding[1] = {...};
expectedPlainData = [NSData dataWithBytes:plainBytesWithPadding length:sizeof(plainBytesWithPadding)];
cipheredData = [AKWAesKeyWrap cipheredDataByWrappingWithPaddingPlainData:expectedPlainData
usingKeyEncryptionKey:keyEncryptionKey
error:nil];
plainData = [AKWAesKeyWrap plainDataByUnwrappingWithPaddingCipheredData:cipheredData
usingKeyEncryptionKey:keyEncryptionKey
error:nil];
XCTAssertEqualObjects(expectedPlainData, plainData);
AesKeyWrap 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。