Skip to content

Commit

Permalink
Merge pull request #6 from DavidBenko/NameChange
Browse files Browse the repository at this point in the history
Change name to DBTransitEncryption
  • Loading branch information
David Benko committed Jun 11, 2014
2 parents e9b072b + e2877bc commit 6202a1b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
10 changes: 5 additions & 5 deletions ObjectiveTLS.podspec → DBTransitEncryption.podspec
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Pod::Spec.new do |s|
s.name = "ObjectiveTLS"
s.name = "DBTransitEncryption"
s.version = "0.1.1"
s.summary = "Encryption for data in transit; ObjectiveTLS will secure data for transit similar to the handshake protocol of TLS."
s.summary = "Encryption for data in transit; DBTransitEncryption will secure data for transit similar to the handshake protocol of TLS."
s.description = <<-DESC
Transport Layer Security for securing data payloads in Objective-C. An easy way to secure data by providing a symmetric key for that transaction. Keys are generated on the fly and every message will have a new key.
DESC
s.homepage = "https://github.com/DavidBenko/Objective-TLS"
s.homepage = "https://github.com/DavidBenko/DBTransitEncryption"
s.license = 'MIT'
s.author = { "David Benko" => "[email protected]" }
s.source = { :git => "https://github.com/DavidBenko/Objective-TLS.git", :tag => s.version.to_s }
s.source = { :git => "https://github.com/DavidBenko/DBTransitEncryption.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/davidwbenko'

s.platform = :ios
s.requires_arc = true

s.source_files = 'ObjectiveTLS'
s.source_files = 'DBTransitEncryption'
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ObjectiveTLS.h
// DBTransitEncryption.h
// DBTransitEncryption
//
// Created by David Benko on 5/9/14.
Expand All @@ -16,7 +16,7 @@
typedef void (^IVMixerBlock) (NSData **data,NSData **key, NSData *iv);
typedef NSData* (^IVSeparatorBlock) (NSData **data, NSData **key);

@interface ObjectiveTLS : NSObject
@interface DBTransitEncryption : NSObject

@property (nonatomic, assign) NSUInteger rsaKeySize; // RSA key size in bits
@property (nonatomic, assign) SecPadding rsaPadding; // RSA padding
Expand All @@ -37,15 +37,15 @@ typedef NSData* (^IVSeparatorBlock) (NSData **data, NSData **key);
* @param base64KeyData The contents of the public key
* @return new ObjectiveTLS instance
*/
- (ObjectiveTLS *)initWithX509PublicKeyData:(NSData *)base64KeyData;
- (DBTransitEncryption *)initWithX509PublicKeyData:(NSData *)base64KeyData;

/**
* Initializes a new ObjectiveTLS object with the contents of a X.509 RSA public key at a given path
*
* @param publicKeyPath The file path of the public key
* @return new ObjectiveTLS instance
*/
- (ObjectiveTLS *)initWithX509PublicKey:(NSString *)publicKeyPath;
- (DBTransitEncryption *)initWithX509PublicKey:(NSString *)publicKeyPath;

#pragma mark - PKCS#12 RSA Private Key (.p12)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ObjectiveTLS.m
// DBTransitEncryption.m
// DBTransitEncryption
//
// Created by David Benko on 5/9/14.
Expand All @@ -10,9 +10,9 @@
// https://github.com/xjunior/XRSA RSA Encryption Algorithms
//

#import "ObjectiveTLS.h"
#import "DBTransitEncryption.h"

@interface ObjectiveTLS (){
@interface DBTransitEncryption (){
SecKeyRef publicKey;
SecKeyRef privateKey;
SecCertificateRef certificate;
Expand All @@ -22,13 +22,13 @@ @interface ObjectiveTLS (){
}
@end

@implementation ObjectiveTLS
@implementation DBTransitEncryption

static NSString * const kObjectiveTLSErrorDomain = @"com.davidbenko.objectivetls";
static NSString * const kObjectiveTLSErrorDomain = @"com.davidbenko.dbtransitencryption";

#pragma mark - Init

- (ObjectiveTLS *)initWithX509PublicKeyData:(NSData *)base64KeyData {
- (DBTransitEncryption *)initWithX509PublicKeyData:(NSData *)base64KeyData {
self = [super init];
if (self) {

Expand All @@ -53,7 +53,7 @@ - (ObjectiveTLS *)initWithX509PublicKeyData:(NSData *)base64KeyData {
return self;
}

- (ObjectiveTLS *)initWithX509PublicKey:(NSString *)publicKeyPath {
- (DBTransitEncryption *)initWithX509PublicKey:(NSString *)publicKeyPath {
if (publicKeyPath == nil) {
NSLog(@"Can not find %@", publicKeyPath);
return nil;
Expand Down
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ObjectiveTLS
DBTransitEncryption
=====================

Overview
Expand All @@ -9,7 +9,7 @@ Transport Layer Security for securing data payloads in Objective-C. An easy way
**TL;DR** AES encrypts data with a random key, RSA encrypts key and provides both.

### What does it do?
**ObjectiveTLS** will secure data for transit similar to the handshake protocol of TLS.
**DBTransitEncryption** will secure data for transit similar to the handshake protocol of TLS.
- Generate AES symmetric key
- Encrypt data payload with AES key
- Encrypt AES key with X.509 RSA public key
Expand All @@ -18,13 +18,13 @@ Transport Layer Security for securing data payloads in Objective-C. An easy way
### Installation

##### Via CocoaPods
- Add `pod 'ObjectiveTLS'` to your podfile
- Add `pod 'DBTransitEncryption'` to your podfile
- Run `pod install`

##### Manual Installation
- Link project against `Security.framework`
- Add `ObjectiveTLS` folder to your project
- Import header (`#import "ObjectiveTLS.h"`)
- Add `DBTransitEncryption` folder to your project
- Import header (`#import "DBTransitEncryption.h"`)

### Generate X.509 RSA Key Pair
- Run the following commands to generate a personal key pair for testing.
Expand All @@ -47,7 +47,7 @@ Encryption
NSString *keyPath = [[NSBundle mainBundle] pathForResource:@"public_key"
ofType:@"der"];

ObjectiveTLS *otls = [[ObjectiveTLS alloc]initWithX509PublicKey:keyPath];
DBTransitEncryption *encryptor = [[DBTransitEncryption alloc]initWithX509PublicKey:keyPath];
```
### Using in-memory X.509 Public Key (Recommended)
Expand All @@ -56,18 +56,18 @@ Encryption
NSString *publicKey = @"MIICs ... kT0=\n"; // Base64 encoded key
NSData *data = [[NSData alloc] initWithBase64EncodedString:publicKey options:NSDataBase64DecodingIgnoreUnknownCharacters];
ObjectiveTLS *otls = [[ObjectiveTLS alloc]initWithX509PublicKeyData:data];
DBTransitEncryption *encryptor = [[DBTransitEncryption alloc]initWithX509PublicKeyData:data];
```

### Encrypt NSString
```objc

ObjectiveTLS *otls = [[ObjectiveTLS alloc]initWithX509PublicKey:keyPath];
DBTransitEncryption *encryptor = [[DBTransitEncryption alloc]initWithX509PublicKey:keyPath];
NSError *err = nil;
NSData *key = nil; // AES Key, Encrypted with RSA public key
NSData *iv = nil; // Randomly Generated IV

NSData *encryptedPayload = [otls aesEncryptString:@"Hello World Text"
NSData *encryptedPayload = [encryptor encryptString:@"Hello World Text"
rsaEncryptedKey:&key
iv:&iv
error:&err];
Expand All @@ -79,12 +79,12 @@ Encryption
NSString *string = @"Hello World Text";
NSData *dataToEncrypt = [string dataUsingEncoding:kStringEncoding];
ObjectiveTLS *otls = [[ObjectiveTLS alloc]initWithX509PublicKey:keyPath];
DBTransitEncryption *encryptor = [[DBTransitEncryption alloc]initWithX509PublicKey:keyPath];
NSError *err = nil;
NSData *key = nil; // AES Key, Encrypted with RSA public key
NSData *iv = nil; // Randomly Generated IV
NSData *encryptedPayload = [otls aesEncryptData:dataToEncrypt
NSData *encryptedPayload = [encryptor encryptData:dataToEncrypt
rsaEncryptedKey:&key
iv:&iv
error:&err];
Expand All @@ -100,8 +100,8 @@ Decryption
NSString *privateKeyPath = [[NSBundle mainBundle] pathForResource:@"private_key" ofType:@"p12"];
NSString *privateKeyPassword = @"Password for .p12 file"

ObjectiveTLS *otls = [[ObjectiveTLS alloc]initWithX509PublicKey:publicKeyPath];
[otls setPrivateKey:privateKeyPath withPassphrase:privateKeyPassword];
DBTransitEncryption *encryptor = [[DBTransitEncryption alloc]initWithX509PublicKey:publicKeyPath];
[encryptor setPrivateKey:privateKeyPath withPassphrase:privateKeyPassword];
```
### Decrypt NSData
Expand All @@ -111,19 +111,19 @@ Decryption
NSData *rsaEncryptedKey; // some encrypted key
NSData *iv = nil; // some iv
ObjectiveTLS *otls = [[ObjectiveTLS alloc]initWithX509PublicKey:publicKeyPath];
[otls setPrivateKey:privateKeyPath withPassphrase:@".p12 password"];
DBTransitEncryption *encryptor = [[DBTransitEncryption alloc]initWithX509PublicKey:publicKeyPath];
[encryptor setPrivateKey:privateKeyPath withPassphrase:@".p12 password"];
NSError *err = nil;
NSData *decryptedPayload = [otls aesDecryptData:dataToEncrypt
NSData *decryptedPayload = [encryptor decryptData:dataToEncrypt
rsaEncryptedKey:key
iv:iv
error:&err];
```

Public Properties
---------
**ObjectiveTLS** has a few public properties which allow you to modify the encryption algorithms to suit your project's needs.
**DBTransitEncryption** has a few public properties which allow you to modify the encryption algorithms to suit your project's needs.

```objc
@property (nonatomic, assign) NSUInteger rsaKeySize; // RSA key size in bits
Expand All @@ -141,7 +141,7 @@ Public Properties

IV Mixer Blocks
---------
**ObjectiveTLS** allows you to define custom blocks to mix and separate the initialization vector with the key and/or the encrypted data.
**DBTransitEncryption** allows you to define custom blocks to mix and separate the initialization vector with the key and/or the encrypted data.

The `ivMixer` gives access to the data, key, and iv immediately after the data is encrypted, but before the key is encrypted. This allows you to mix the iv with key before it is RSA encrypted, to further secure the iv.

Expand All @@ -150,19 +150,19 @@ The `ivSeparator` is the opposite of the `ivMixer`. The `ivSeparator` should be
### IV Mixing Example
```objc

ObjectiveTLS *otls = [[ObjectiveTLS alloc]initWithX509PublicKeyData:pubkeyb64data];
DBTransitEncryption *encryptor = [[DBTransitEncryption alloc]initWithX509PublicKeyData:pubkeyb64data];

// Prepends the iv to the key before the key is encrypted

[otls setIvMixer:^(NSData **data,NSData **key, NSData *iv){
[encryptor setIvMixer:^(NSData **data,NSData **key, NSData *iv){
NSMutableData *mutableKey = [iv mutableCopy];
[mutableKey appendBytes:[*key bytes] length:[*key length]];
*key = mutableKey;
}];

// Extracts the iv from the key before decryption

[otls setIvSeparator:^NSData *(NSData **data, NSData **key){
[encryptor setIvSeparator:^NSData *(NSData **data, NSData **key){
NSInteger ivSize = 16;
NSMutableData *mutableKey = [*key mutableCopy];
NSRange range = NSMakeRange(0, ivSize);
Expand Down

0 comments on commit 6202a1b

Please sign in to comment.