AesKeyWrap 1.1.3

AesKeyWrap 1.1.3

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2016年12月

Enrique de la Torre维护。



  • 作者
  • Enrique de la Torre

AES Key Wrap (RFC 3394) 和 AES Key Wrap with Padding (RFC 5649) 算法的 ObjC 实现。

注意

CommonCrypto 已提供一些实现 RFC 3394 的函数

  • CCSymmetricKeyWrap
  • CCSymmetricKeyUnwrap

但它还没有提供任何实现带填充的包装的函数 (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 文件。