Coder Social home page Coder Social logo

joeymeyer / pbkdf2-wrapper Goto Github PK

View Code? Open in Web Editor NEW
32.0 1.0 3.0 97 KB

An Objective-C interface for the PBKDF2 implementation in CommonCrypto.

License: MIT License

Objective-C 93.67% Ruby 6.33%
pbkdf2 objective-c commoncrypto ios macos watchos

pbkdf2-wrapper's Introduction

PBKDF2-Wrapper

Version Platform License

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

  1. Install via CocoaPods
pod 'PBKDF2-Wrapper'
  1. Import the public header
#import <PBKDF2-Wrapper/PBKDF2-Wrapper.h>

##Requirements

  • iOS 6.0
  • OSX 10.8
  • watchOS 2.0

Tests

Build Status

To run tests pull down the repository and run the following commands:

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

Creator

Joey Meyer

License

PBKDF2-Wrapper is available under the MIT license. See the LICENSE file for more info.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.