Latest 0.1.1
Homepage https://github.com/DimensionDev/DMSOpenPGP
License AGPL
Platforms ios 11.0
Dependencies BouncyCastle-ObjC, OpenSSL-Universal
Authors

Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

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

pod 'DMSOpenPGP'

Usage

Setup

import BouncyCastle_ObjC

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    // Add provider before use DMSOpenPGP (also add to extension if have)
    JavaSecuritySecurity.addProvider(with: BCJceProviderBouncyCastleProvider())

    return true
}

Keygen

do {
    let generateKeyData = GenerateKeyData(name: "Hello", email: "[email protected]", password: "Alice",
                                          masterKey: KeyData(), subkey: KeyData())
    let alice = try DMSPGPKeyRingFactory(generateKeyData: generateKeyData).keyRing
    let armoredPublicKey = alice.publicKeyRing.armored()
    let armoredSecretKey = alice.secretKeyRing.armored()
} catch {
    …
}

Encrypt & Sign

// encrypt
guard let secretKeyRing = alice.secretKeyRing else {
    return
}

do {
    // with signature
    let encryptor = try DMSPGPEncryptor(publicKeyRings: [alice.publicKeyRing, bob.publicKeyRing, eve.publicKeyRing],
                                        secretKeyRing: secretKeyRing,
                                        password: "Alice")
    let encryptedWithSignatureMessage = try encryptor.encrypt(message: "Message")

    // without signature
    let encryptor2 = try DMSPGPEncryptor(publicKeyRings: [alice.publicKeyRing, bob.publicKeyRing, eve.publicKeyRing])
    let encryptedWithoutSignatureMessage = try encryptr2.encrypt(message: "Message")

} catch {
   …
}
// Sign
guard let secretKeyRing = alice.secretKeyRing else {
    return
}

do {
    let encryptor = try DMSPGPEncryptor(secretKeyRing: secretKeyRing, password: "Alice")
    let cleartext = try encryptor.encrypt(message: "Message")
    // or
    let signer = try  DMSPGPSigner(secretKeyRing: keyRing.secretKeyRing, password: password)
    let cleartext2 = signer.sign(message: "Message")
} catch {
    …
}

Decrypt & Verify

do {
    let decryptor = try DMSPGPDecryptor(armoredMessage: encryptedMessage)
    // decryptor.encryptingKeyIDs contains all decryptable secret keys' keyID   
    let decryptKey = decryptor.encryptingKeyIDs.compactMap { keyID in
        return alice.secretKeyRing?.getDecryptingSecretKey(keyID: keyID)
    }.first

    guard let secretKey = decryptKey else { 
        return
    }

    let message = try decryptor.decrypt(secretKey: secretKey, password: "Alice")
    let signatureVerifier = DMSPGPSignatureVerifier(message: message, onePassSignatureList: decryptor.onePassSignatureList, signatureList: decryptor.signatureList)
    let verifyResult = signatureVerifier.verifySignature(use: alice.publicKeyRing)
}

Please check DMSOpenPGP/Tests/DMSOpenPGPTests.swift in Example Pods unit tests to see more details.

Dependencies

License

DMSOpenPGP is available under the AGPL license. See the LICENSE file for more info.

Latest podspec

{
    "name": "DMSOpenPGP",
    "version": "0.1.1",
    "summary": "Swift wrapper for Bouncy Castle OpenPGP.",
    "description": "Swift wrapper for Bouncy Castle OpenPGP. Supports PGP keygen, encrypt & sign, decrypt & verify.",
    "homepage": "https://github.com/DimensionDev/DMSOpenPGP",
    "license": {
        "type": "AGPL",
        "file": "LICENSE"
    },
    "authors": {
        "CMK": "[email protected]"
    },
    "source": {
        "git": "https://github.com/DimensionDev/DMSOpenPGP.git",
        "tag": "0.1.1"
    },
    "swift_versions": "5.0",
    "platforms": {
        "ios": "11.0"
    },
    "requires_arc": false,
    "source_files": "DMSOpenPGP/Classes/**/*",
    "xcconfig": {
        "LIBRARY_SEARCH_PATHS": ""${PODS_ROOT}/BouncyCastle-ObjC/dist/lib"",
        "HEADER_SEARCH_PATHS": ""${PODS_ROOT}/BouncyCastle-ObjC/dist/frameworks/JRE.framework/Headers""
    },
    "dependencies": {
        "BouncyCastle-ObjC": [
            "~> 0.1.0"
        ],
        "OpenSSL-Universal": [
            "~> 1.0.2.17"
        ]
    },
    "static_framework": true,
    "swift_version": "5.0",
    "testspecs": [
        {
            "name": "Tests",
            "test_type": "unit",
            "source_files": "DMSOpenPGP/Tests/**/*",
            "dependencies": {
                "ConsolePrint": []
            }
        }
    ]
}

Pin It on Pinterest

Share This