PBKDF2-Wrapper provides a very simple Objective-C interface for the CommonCrypto implementation of the PBKDF2 algorithm.
Derive an encryption key from a password. PBKDF2Result
automatically handles creating a secure random salt, and calibrating the number of rounds to take approximately 100ms to derive the key.
NSString *password = ...;
PBKDF2Result *result = [[PBKDF2Result alloc] initWithPassword:password];
NSData *encryptionKey = result.derivedKey;
Afterwards you can conveniently archive the configuration which includes information such the key length, salt, number of rounds, and the pseudo random function that was used when deriving the key.
[NSKeyedArchiver archiveRootObject:result.configuration
toFile:@"/path/to/file"];
Next launch you can grab the archived configuration file and use that when deriving the key.
PBKDF2Configuration *configuration = [NSKeyedUnarchiver unarchiveObjectWithFile:@"/path/to/file"];
NSString *password = ...;
PBKDF2Result *result = [[PBKDF2Result alloc] initWithPassword:password
configuration:configuration];
NSData *encryptionKey = result.derivedKey;
In addition you can also explicitly create the configuration using a number of helpful initializers. Here is an example:
NSData *salt = ...;
[[PBKDF2Configuration alloc] initWithSalt:salt
derivedKeyLength:16
rounds:20000
pseudoRandomFunction:PBKDF2PseudoRandomFunctionSHA256];
- Install via CocoaPods
pod 'PBKDF2-Wrapper'
- Import the public header
#import <PBKDF2-Wrapper/PBKDF2-Wrapper.h>
##Requirements
- iOS 6.0
- OSX 10.8
- watchOS 2.0
To run tests pull down the repository and run the following commands:
$ bundle install
$ bundle exec rake test:prepare
$ bundle exec rake
PBKDF2-Wrapper is available under the MIT license. See the LICENSE file for more info.