PBKDF2-Wrapper 0.1.2

PBKDF2-Wrapper 0.1.2

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布了最后发布2015年11月

Joey Meyer维护。



PBKDF2-Wrapper 提供了一个非常简单的 Objective-C 接口,用于 CommonCrypto 实现的 PBKDF2 算法。

使用方法

生成密钥

从密码生成加密密钥。 PBKDF2Result 将自动处理创建安全的随机盐并调整迭代次数,以大约 100ms 的时间生成密钥。

NSString *password = ...;
PBKDF2Result *result = [[PBKDF2Result alloc] initWithPassword:password];
NSData *encryptionKey = result.derivedKey;

保存配置

之后,您可以方便地归档配置,其中包含有关密钥长度、盐、迭代次数以及生成密钥时使用的伪随机函数等信息。

[NSKeyedArchiver archiveRootObject:result.configuration
                            toFile:@"/path/to/file"];

加载保存的配置

下次启动时,您可以从归档配置文件中检索该文件,并在生成密钥时使用。

PBKDF2Configuration *configuration = [NSKeyedUnarchiver unarchiveObjectWithFile:@"/path/to/file"];

NSString *password = ...;
PBKDF2Result *result = [[PBKDF2Result alloc] initWithPassword:password
                                                configuration:configuration];
NSData *encryptionKey = result.derivedKey;

显式创建配置

您还可以使用多个有用的初始化器显式地创建配置。以下是一个示例

NSData *salt = ...;

[[PBKDF2Configuration alloc] initWithSalt:salt
                         derivedKeyLength:16
                                   rounds:20000
                     pseudoRandomFunction:PBKDF2PseudoRandomFunctionSHA256];

安装

  1. 通过 CocoaPods 安装

    pod 'PBKDF2-Wrapper'
  2. 导入公共头文件

    #import <PBKDF2-Wrapper/PBKDF2-Wrapper.h>

要求

  • iOS 6.0
  • OSX 10.8
  • watchOS 2.0

测试

要运行测试,请拉取仓库并运行以下命令:

$ bundle install
$ bundle exec rake test:prepare
$ bundle exec rake

创建者

Joey Meyer

许可证

PBKDF2-Wrapper 采用 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。