objectivepgp

Introduction

Welcome to the official documentation for objectivepgp, a library for working with OpenPGP encryption and decryption in Objective-C.

Installation

To install objectivepgp, follow the steps below:

  1. Open your project in Xcode.
  2. Go to File > Swift Packages > Add Package Dependency.
  3. Enter the URL of the objectivepgp package repository: https://github.com/krzyzanowskim/objective-pgp.git.
  4. Choose the desired version rule for your project.
  5. Click Next and wait for Xcode to resolve the package.
  6. Once resolved, select the objectivepgp package and add it to your target.

Usage

To start using objectivepgp in your project, follow the steps below:

Step 1: Import the module

In the source file where you want to use objectivepgp, import the module:

// Swift
import ObjectivePGP

// Objective-C
@import ObjectivePGP;

Step 2: Generate a Key Pair

To generate a new OpenPGP key pair, use the generate() method:

let key = ObjectivePGP.generate()

Step 3: Encrypt a Message

To encrypt a message using a public key, use the encrypt() method:

let publicKey = try ObjectivePGP.readKeys(from: publicKeyFilePath).first!

let encryptedData = try ObjectivePGP.encrypt("Hello, World!".data(using: .utf8)!, using: [publicKey])

Step 4: Decrypt a Message

To decrypt a message using a private key, use the decrypt() method:

let privateKey = try ObjectivePGP.readKeys(from: privateKeyFilePath).first!

let decryptedData = try ObjectivePGP.decrypt(encryptedData, andVerifySignature: false, using: privateKey, passphraseForKey: "passphrase")

API Reference

The objectivepgp library provides the following main classes and methods:

ObjectivePGP

A class for managing the OpenPGP operations.

// Generate a key pair
  static func generate() -> ObjectivePGP.KeyPair

  // Encrypt a message using public keys
  static func encrypt(_ data: Data, using keys: [ObjectivePGP.Key]) throws -> Data

  // Decrypt a message using a private key
  static func decrypt(_ data: Data, andVerifySignature: Bool, using key: ObjectivePGP.Key, passphraseForKey: String?) throws -> Data

  // Read keys from file path
  static func readKeys(from filePath: String) throws -> [ObjectivePGP.Key]
  

ObjectivePGP.Key

A class representing an OpenPGP key.

// Key ID
  var keyID: String? { get }

  // Users associated with the key
  var users: [ObjectivePGP.UserID] { get }
  

ObjectivePGP.KeyPair

A class representing a pair of OpenPGP keys (public and private).

// Public key
  var publicKey: ObjectivePGP.Key { get set }

  // Private key
  var privateKey: ObjectivePGP.Key { get set }
  

Further Help

If you need further assistance or have any questions, please consider checking out the official GitHub repository at https://github.com/krzyzanowskim/objective-pgp or reaching out to the objectivepgp community for support.