• Stars
    star
    667
  • Rank 67,625 (Top 2 %)
  • Language
    Objective-C
  • License
    Other
  • Created over 10 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ObjectivePGP is an open-source library for iOS and macOS that provides developers with tools for implementing OpenPGP encryption and decryption, digital signing, and signature verification in their applications, thereby enhancing security and data integrity.

objectivepgp

CocoaPods Compatible Swift Package Manager compatible Platform Twitter

ObjectivePGP is an implementation of OpenPGP protocol for iOS and macOS. OpenPGP is the most widely used email encryption standard. It is defined by the OpenPGP Working Group of the Internet Engineering Task Force (IETF).

Here is the blog post story.

How do I get involved?

You want to help, great! Go ahead and fork our repo, make your changes and send us a pull request.

Contribution

You are welcome to contribute. See CONTRIBUTING.md
Please create Pull Request.

The license

The ObjectivePGP stays under a dual license:

  • Free for non-commercial use, covered by the variant of BSD license. That means you have to mention Marcin Krzyżanowski as the original author of this code and reproduce the LICENSE text inside your app.

  • Commercial-use license to use in commercial products. Please bear in mind that some free products remain commercial products. Please contact me via email for details.

Not sure what to choose? check FAQ

Installation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/krzyzanowskim/ObjectivePGP.git", .upToNextMinor(from: "0.99.4"))
]

CocoaPods

pod 'ObjectivePGP'

Frameworks

ObjectivePGP comes with the Frameworks for the latest release, you can copy and embed in your project:

Usage

Objective-C

#import <ObjectivePGP/ObjectivePGP.h>

Swift

import ObjectivePGP
Read keys (private or public)
NSArray<PGPKey *> *keys = [ObjectivePGP readKeysFromPath:@"/path/to/key.asc" error:nil];
let keys = try ObjectivePGP.readKeys(fromPath: "/path/to/key.asc")
Keyring

Keyring is a storage (in memory or on disk) that keep all sorts of PGP keys.

PGPKeyring *keyring = ObjectivePGP.defaultKeyring;
PGPKeyring *keyring = [[PGPKeyring alloc] init];

NSArray<PGPKey *> *allKeys = keyring.keys;
[keyring importKeys:@[key]];
[keyring deleteKeys:@[key]];

[keyring importKey:@"979E4B03DFFE30C6" fromPath:@"/path/to/secring.gpg"];
PGPKey *key = [keyring findKeyWithIdentifier:@"979E4B03DFFE30C6"];
NSArray<PGPKey *> keys = [pgp findKeysForUserID:@"Name <[email protected]>"];
let keyring = ObjectivePGP.defaultKeyring
let keyring = Keyring()

let allKeys = keyring.keys
keyring.import(keys: [key])
keyring.delete(keys: [key])

keyring.import(keyIdentifier:"979E4B03DFFE30C6", fromPath:"/path/to/secring.gpg")
if let key = keyring.findKey("979E4B03DFFE30C6") {
	// key found in keyring
}

keyring.findKeys("Name <[email protected]>").forEach(key) {
	// process key
}
Export keys (private or public)
// Write keyring to file
[[keyring export:error] writeToURL:[NSURL fileURLWithString:@"keyring.gpg"]];

// Public keys data
NSData *publicKeys = [keyring exportKeysOfType:PGPKeyTypePublic error:nil];
// Write keyring to file
try keyring.export().write(to: URL(fileURLWithPath: "keyring.gpg"))

// Public keys (Data)
let publicKeys = keyring.exportKeys(of: .public)
Sign & verify data (or file)

Sign a data with a key:

NSData *signature = [ObjectivePGP sign:fileContent detached:YES usingKeys:@[key] passphraseForKey:nil error:nil];
[ObjectivePGP verify:fileContent withSignature:signature usingKeys:@[key] passphraseForKey:nil error:nil];
let signature = try ObjectivePGP.sign(encryptedBin, detached:true, using: [key1])
try ObjectivePGP.verify(encryptedBin, withSignature: signature, using: [key1])
Encrypt & Decrypt
NSData *encrypted = [ObjectivePGP encrypt:fileContent addSignature:YES usingKeys:@[key] passphraseForKey:nil error:nil];
[ObjectivePGP decrypt:encrypted andVerifySignature:YES usingKeys:@[key] passphraseForKey:nil error:nil];
let encrypted = try ObjectivePGP.encrypt(fileContent), addSignature: true, using: [key1, key2])
let decrypted = try ObjectivePGP.decrypt(encrypted, andVerifySignature: true, using: [key1])
Generate new key pair
PGPKeyGenerator *generator = [[PGPKeyGenerator alloc] init];
PGPKey *key = [generator generateFor:@"Marcin <[email protected]>" passphrase:nil];
NSData *publicKeyData = [key export:PGPKeyTypePublic error:nil];
NSData *secretKeyData = [key export:PGPKeyTypeSecret error:nil];
let key = KeyGenerator().generate(for: "[email protected]", passphrase: "password")
let publicKey = try key.export(keyType: .public)
let secretKey = try key.export(keyType: .secret)

ASCII Armor

ASCII armor is a binary-to-textual encoding converter. ASCII armor involves encasing encrypted messaging in ASCII so that they can be sent in a standard messaging format such as email.

Example:

-----BEGIN PGP PUBLIC KEY BLOCK-----
Comment: For more info see https://www.objectivepgp.org

[...]
-----END PGP PUBLIC KEY BLOCK-----

Class PGPArmor can be used to convert binary format to ASCII format

NSString *armoredKey = [PGPArmor armoredData:encrypted as:PGPArmorPublicKey];
let armoredKey = Armor.armored(Data(), as: .publicKey)

When convert manually, it is important to use right PGPArmorType value that define the header. It may be a tricky part so here's the cheatsheet:

Type data PGPArmorType Example
Encrypted PGPArmorMessage Armor.armored(ObjectivePGP.encrypt(...), as: .message)
Decrypted PGPArmorMessage Armor.armored(ObjectivePGP.decrypt(...), as: .message)
Public key PGPArmorTypePublic Armor.armored(key.export(), as: .publicKey)
Secret key PGPArmorTypeSecret Armor.armored(key.export(), as: .secretKey)

For any result of encryption the type is PGPArmorMessage

Changelog

See CHANGELOG

Known limitations:

  • Cleartext signature.

Security Audit

To date the ObjectivePGP code base has undergone a complete security audit from Cure53.

Acknowledgment

This product uses software developed by the OpenSSL Project for use in the OpenSSL Toolkit. (http://www.openssl.org/)

Author

Marcin Krzyżanowski

More Repositories

1

CryptoSwift

CryptoSwift is a growing collection of standard and secure cryptographic algorithms implemented in Swift
Swift
10,176
star
2

Natalie

Natalie - Storyboard Code Generator (for Swift)
Swift
1,167
star
3

STTextView

Performant and reusable text view component (TextKit 2), with line numbers and more. UITextView / NSTextView replacement.
Swift
1,073
star
4

OpenSSL

OpenSSL package for SwiftPM, CocoaPod, and Carthage, multiplatform
C
919
star
5

OnlineSwiftPlayground

Online Swift Playground
Swift
245
star
6

CoreTextSwift

CoreText Swift bindings
Swift
158
star
7

NSTableView-Sections

NSTableView with sections (similar to UITableView)
Swift
89
star
8

SwiftUI.TextEdit

SwiftUI proof-of-concept text edit component
Swift
87
star
9

JSONCodable

JSON Codable is what we need 90% of the time
Swift
75
star
10

unnetpgp

*Deprecated* NetPGP wrapper. Use ObjectivePGP
C
67
star
11

reorder

Reorder Swift functions
Swift
57
star
12

SwiftUI.AnimatedImage

SwiftUI AnimatedImage View
Swift
56
star
13

SwiftUI.SplitView

Swift
48
star
14

RepetitiveTask

Swift
40
star
15

tree-sitter-xcframework

binary build of tree-sitter for apple platforms
C
37
star
16

BoyerMoore

Boyer-Moore algorithm sample
Swift
37
star
17

GeneratedResults-UITableView

Practical Swift: pages generator - build once, use many
Swift
36
star
18

STTextView-Plugin-Neon

Source Code Syntax Highlighting
C
33
star
19

STTextKitPlus

Collection of TextKit 2 helpers used to build STTextView.
Swift
28
star
20

MKDataScanner

NSScanner for NSData and files.
Objective-C
16
star
21

antlr-swift-playground

Antlr Swift Parser playground
Swift
14
star
22

CollectionSafeIndex

Get the element at the specified index only if it is within bounds, otherwise nil
Swift
11
star
23

CoreTextWorkshop

Take a look at the CoreText API - a foundation of layout and drawing text on macOS and iOS. In this workshop we’ll attempt to build Text Label (akin UILabel), learn about layers of CoreText API and how to use it.
Swift
10
star
24

AES256CBC

Most convenient AES256-CBC encryption for Swift 2 & 3
Swift
8
star
25

OpenSSL-Package

OpenSSL package for SwiftPM
Swift
8
star
26

RawData

Swift RawData CollectionType
Swift
7
star
27

STTextView-Plugin-Annotations

Annotations Plugin
Swift
7
star
28

STTextView-Plugin-Template

Template Plugin repository for STTextView
Swift
7
star
29

CodeEditView

custom text view implementation
Swift
6
star
30

Kitura-Session-Kuery

Kitura-Session store using Swift-Kuery (SQL database abstraction layer) as the backing store
Swift
6
star
31

CloudKitWebServices

CloudKit Web Services framework for everyone else...
6
star
32

TouchImageView

iOS UIImageView with convenient touch delegate
Objective-C
6
star
33

language-server-protocol

Language Server Protocol
Swift
6
star
34

sendable.wtf

HTML
5
star
35

Google1Password

1Password integration for Google sign-in view.
Objective-C
5
star
36

ChorusBirdie

Birdie singing songs game. SwiftCrunch hackathon project. Created over few hours from zero.
Swift
3
star
37

monaco-editor-vue-component

MonacoEditor component for Vue.js
Vue
2
star
38

AppleRadar-FileProviderEnumeratorNotificationSample

NSFileProviderManager.signalEnumerator does not trigger update of UIDocumentBrowserViewController
Swift
2
star
39

GNUGadu

GNU Gadu is instant messaging client designed to work with protocols common in Poland (but not only). Contrary to its name, is not part of the GNU project.
C
2
star
40

MKScrollView

Alternative to UIScrollView. Proof of concept implementation.
Objective-C
1
star