TPCocoaGPG 0.2.3

TPCocoaGPG 0.2.3

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
Released最后发布2015年2月

Thomas Pelletier 维护。



  • 作者:
  • Thomas Pelletier

围绕 GPG 的 Objective-C 封装。

这个库旨在成为简单、易于使用的库,以便处理 GPG。它并不试图全面,也不会删除 GPG 二进制文件。

安装

安装此库的推荐方法是使用 CocoaPods

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

使用

请参阅 TPCocoaGPG.h 以获取完整 API。请参阅 TPCocoaGPGSpecs.m 以获取用法示例。

初始化

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

列出密钥

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

按指纹加载密钥

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

加密

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

解密

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

检查密码短语是否能解锁密钥

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

将密钥导入密钥环

NSString* fingerprint = [gpg importIntoKeyring:key];

生成密钥对

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

导出密钥

武装 ASCII 输出。

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

更改密码短语

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

开发

安装开发依赖项: pod install。打开工作区并运行测试。

许可证

MIT。请参阅 LICENSE。