Skip to content

christophherrmann/AesGcm

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AesGcm

CI Status codecov.io Version Docs License

ObjC implementation of Galois/Counter Mode (GCM) with Advanced Encryption System (AES).

Notice

As pointed out in this comment in StackOverflow, iOS already has some GCM crypt functions, however they are not public. In the mean time, you can use the methods in this repo.

The documents used as guide to code this algorithm were:

Installation

AesGcm is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "AesGcm"

Usage

#import "IAGAesGcm.h"

u_char keyBytes[16] = {...};
NSData *key = [NSData dataWithBytes:keyBytes length:sizeof(keyBytes)];

u_char ivBytes[12] = {...};
NSData *iv = [NSData dataWithBytes:ivBytes length:sizeof(ivBytes)];

NSData *aad = [@"AdditionalAuthenticatedData" dataUsingEncoding:NSUTF8StringEncoding];

// Authenticated Encryption Function
NSData *expectedPlainData = [@"PlainData" dataUsingEncoding:NSUTF8StringEncoding];

IAGCipheredData *cipheredData = [IAGAesGcm cipheredDataByAuthenticatedEncryptingPlainData:expectedPlainData
                                                          withAdditionalAuthenticatedData:aad
                                                                  authenticationTagLength:IAGAuthenticationTagLength128
                                                                     initializationVector:iv
                                                                                      key:key
                                                                                    error:nil];

// Authenticated Decryption Function
NSData *plainData = [IAGAesGcm plainDataByAuthenticatedDecryptingCipheredData:cipheredData
                                              withAdditionalAuthenticatedData:aad
                                                         initializationVector:iv
                                                                          key:key
                                                                        error:nil];

XCTAssertEqualObjects(expectedPlainData, plainData);

License

AesGcm is available under the MIT license. See the LICENSE file for more info.

About

Galois/Counter Mode (GCM) with Advanced Encryption System (AES).

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Objective-C 92.7%
  • Shell 6.4%
  • Other 0.9%