Skip to content
Snippets Groups Projects
Select Git revision
  • 5f9d98a061042f83b7c2458be0e7fd2bd7d5e9e9
  • dev default protected
  • 316-tracking-estimator
  • Thesis_hannes_merge_ready_versuch1
  • InboxWithNewOverview
  • 298-missing-backend-features-connections-for-ui
  • 293-integrate-attachment-functionality-in-new-composeview
  • 299-add-pull-to-refresh-to-maillistview
  • 290+Dev
  • 290-redesign-the-ContactView
  • 291-add-research-face-prototype
  • 292-add-comments-to-attachmentviewmain-swift
  • 302-fix-bug-attachment-previews-of-incoming-mails
  • 288-make-folders-list-slide-in-from-the-left-instead-of-from-the-right
  • 295-inboxview-maillistview-improvements
  • 294-fix-bugs-in-new-composeview
  • 287-redesign-composeview
  • updatePGP
  • 282-Implement-missing-functions-in-reply-button
  • 286-update-openssl
  • ThesisHannesV2_
  • runnable
  • optional_UI_change
  • dep
  • NoTestCase
25 results

ObjectivePGP.framework

  • Clone with SSH
  • Clone with HTTPS
  • user avatar
    Oliver Wiese authored
    f666f58d
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.

    objectivepgp

    CocoaPods Compatible Platform Swift 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

    Usage

    #import <ObjectivePGP/ObjectivePGP.h>
    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@example.com>"];
    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@example.com>").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 <marcin@example.com>" passphrase:nil];
    NSData *publicKeyData = [key export:PGPKeyTypePublic error:nil];
    NSData *secretKeyData = [key export:PGPKeyTypeSecret error:nil];
    let key = KeyGenerator().generate(for: "marcin@example.com", 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 http://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

    Installation

    CocoaPods

    target 'TargetName' do
        use_frameworks!
        pod 'ObjectivePGP'
    end

    ObjectivePGP.framework

    ObjectivePGP comes with the Frameworks for the latest release.

    1. Download latest ObjectivePGP.framework or build a framework with the build-frameworks.sh script.
    2. Add a New Copy Files Phase by selecting the Add icon, highlighted in Figure 4. Set the Destination field to Frameworks, and add the framework to the list (see Embedding Frameworks In An App). Ensure Code Sign on Copy is checked. Figure 4
    3. Link framework with the target
      • Add ObjectivePGP.framework to "Link Binary With Libraries" list for the target. screen shot 2017-06-30 at 02 20 47
    4. Link libraries and frameworks
      1. Add Security.framework to "Link Binary With Libraries" list for the target. These are system libraries.
      2. Add libz and libbz2 to "Link Binary With Libraries" list for the target. These are system libraries.
    5. In the Build Phases tab, click the + button at the top and select “New Run Script Phase”. Enter the following code into the script text field:
    bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/ObjectivePGP.framework/Code=8"

    (The last step, is required for working around an iOS App Store bug when archiving universal binaries.)

    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