Skip to content

billp/VPCCMCrypt

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
lib
 
 
 
 
 
 
 
 

VPCCMCrypt

AES/CCM library in Objective-C with Streaming Support

Features

  • AES/128 - ECB Mode
  • Stream Encryption/Decryption methods which allows you to upload each chunk of data to server
  • Data to Data Encryption/Decryption methods
  • File to File Encryption/Decryption methods
  • It uses only 16kb of memory (for stream operations)

#Installation

Add these lines to your Podfile

platform :ios, '6.0'
pod 'VPCCMCrypt', '~> 0.0.1'

Initialization

NSData *key = ...
NSData *iv = ...
NSData *adata = ...
NSInteger tagLength = ...

VPCCMCrypt *ccm = [[VPCCMCrypt alloc] initWithKey:key
                                               iv:iv
                                            adata:adata
                                        tagLength:tagLength];

How to use

Data to Data Encryption

NSData *plainData = ...

[ccm encryptDataWithData:plainData 
           finishedBlock:^(NSData *data) {
           //Do something with data
} errorBlock:^(NSError *error) {
        NSLog(@"Encryption Error: %@", error);
}];

Data to Data Decryption:

NSData *encryptedData = ...

[ccm decryptDataWithData:encryptedData 
           finishedBlock:^(NSData *data) {
        //Do something with data
} errorBlock:^(NSError *error) {
        NSLog(@"Decryption Error: %@", error);
}];

File to File Encryption

NSURL *sourceURL = ...
NSURL *destinationURL = ...

[ccm encryptFileToFileWithSourceURL:sourceURL
                            destUrl:destinationURL
                      finishedBlock:^{
                          //Encryption finished
                      } errorBlock:^(NSError *error) {
                          NSLog(@"Encryption Error: %@", error);
                      }];

File to File Decryption:

NSURL *sourceURL = ...
NSURL *destinationURL = ...

[ccm decryptFileToFileWithSourceURL:sourceURL
                            destUrl:destinationURL
                      finishedBlock:^{
                          //Decryption finished
                      } errorBlock:^(NSError *error) {
                          NSLog(@"Encryption Error: %@", error);
                      }];

Stream Encryption

NSURL *fileUrl = ...

[ccm encryptStreamWithUrl:fileUrl
                dataBlock:^(NSData *data, BOOL isLastBlock) {
                    if (isLastBlock) {
                        //data = TAG
                    }
                    //Upload data to server
                    
                } errorBlock:^(NSError *error) {
                    NSLog(@"Encryption Error: %@", error);
                }];

Stream Decryption

NSURL *fileUrl = ...

[ccm decryptStreamWithUrl:fileUrl
                dataBlock:^(NSData *data, BOOL isLastBlock) {
                    //Do something with the decrypted data
                    
                } errorBlock:^(NSError *error) {
                    NSLog(@"Decryption Error: %@", error);
                }];

Contributors

Special thanks to Thanos Chatziathanasiou (tchatzi@arx.net) for his implementation in Perl

About

AES/CCM Implementation in Objective-C with Streaming Support

Resources

License

Stars

Watchers

Forks

Packages

No packages published