PBKDF2-Wrapper
PBKDF2-Wrapper copied to clipboard
An Objective-C interface for the PBKDF2 implementation in CommonCrypto.
PBKDF2-Wrapper
PBKDF2-Wrapper provides a very simple Objective-C interface for the CommonCrypto implementation of the PBKDF2 algorithm.
Usage
Derive Key
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;
Save Configuration
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"];
Load Saved Configuration
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;
Explicit Configuration Creation
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];
Installation
- 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
Tests
To run tests pull down the repository and run the following commands:
$ bundle install
$ bundle exec rake test:prepare
$ bundle exec rake
Creator
License
PBKDF2-Wrapper is available under the MIT license. See the LICENSE file for more info.