Skip to content

fpillet/TPCocoaGPG

 
 

Repository files navigation

TPCocoaGPG

Pod Version Pod Platform License

Objective-C wrapper around GPG.

This library aims to be a simple, easy to use library to deal with GPG. It does not try to be complete, nor to get rid of the GPG binary.

Installation

The recommended way to install this library is CocoaPods:

pod 'TPCocoaGPG', :git => 'https://github.com/pelletier/TPCocoaGPG.git', :branch => :master

Usage

See TPCocoaGPG.h for the full API. See TPCocoaGPGSpecs.m for usage examples.

Initialization

#import <TPCocoaGPG.h>
TPCocoaGPG* gpg = [[TPCocoaGPG] initGpgPath:@"/usr/local/bin/gpg" andHome:@"/tmp"];

List keys

NSArray* keys = [gpg listPublicKeys];
NSArray* keys = [gpg listSecretKeys];

Load key by fingerprint

TPGPGKey* key = [gpg getPublicKeyWithFingerprint:@"F2479DE6CFB6B695"];
TPGPGKey* key = [gpg getSecretKeyWithFingerprint:@"F2479DE6CFB6B695"];

Encrypt

NSData* encrypted = [gpg encryptData:data withKey:key andPassphrase:@"pass"];
NSData* encrypted = [gpg encryptData:data withKey:key];

Decrypt

NSData* decrypted = [gpg decryptData:data withKey:key andPassphrase:@"pass"];
NSData* decrypted = [gpg decryptData:data withKey:key];

Check if a passphrase unlocks a key

BOOL unlocks = [gpg checkIfPassphrase:@"pass" unlocksKey:key];

Import a key into the keyring

NSString* fingerprint = [gpg importIntoKeyring:key];

Generate keys pair

NSString* fingerprint = [gpg generateKeysWithLength:length
                                              email:@"test@example.com"
                                               name:@"example"
                                            comment:@"example"
                                      andPassphrase:@"qweqwe"];

Export a key

Armored ASCII output.

NSString* fingerprint = [gpg generateKeysWithLength:length
                                              email:@"test@example.com"
                                               name:@"example"
                                            comment:@"example"
                                      andPassphrase:@"qweqwe"];
// can be Public or Private
TPGPGKey* key = [gpg getPublicKeyWithFingerprint:fingerprint];
NSData* data = [gpg exportKey:key];

Change passphrase

NSString* fingerprint = [gpg generateKeysWithLength:length
                                              email:@"test@example.com"
                                               name:@"example"
                                            comment:@"example"
                                      andPassphrase:@"qweqwe"];
TPGPGKey* key = [gpg getSecretKeyWithFingerprint:fingerprint];
[gpg changePassphraseFor:key withOldPassphrase:@"qweqwe" toNewPassphrase:@"foobar"];

Development

Install development dependencies: pod install. Open the workspace and run the tests.

License

MIT. See LICENSE.

About

GPG wrapper for Objective-C

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 97.0%
  • Ruby 3.0%