### ObjectivePGP Installation Source: https://github.com/krzyzanowskim/objectivepgp/blob/main/README.md Instructions for installing ObjectivePGP using Swift Package Manager and CocoaPods. ```swift dependencies: [ .package(url: "https://github.com/krzyzanowskim/ObjectivePGP.git", .upToNextMinor(from: "0.99.4")) ] ``` ```ruby pod 'ObjectivePGP' ``` -------------------------------- ### Installation Source: https://github.com/krzyzanowskim/objectivepgp/blob/main/Frameworks/iphoneos/ObjectivePGP.xcframework/README.md Provides instructions for installing the ObjectivePGP library using Swift Package Manager and CocoaPods. ```APIDOC ## Installation ### Description Instructions for integrating ObjectivePGP into your project using Swift Package Manager or CocoaPods. ### Method N/A (Installation Instructions) ### Endpoint N/A ### Parameters N/A ### Request Example #### Swift Package Manager ``` dependencies: [ .package(url: "https://github.com/krzyzanowskim/ObjectivePGP.git", .upToNextMinor(from: "0.17.0")) ] ``` #### CocoaPods ```` pod 'ObjectigePGP' ```` ### Frameworks ObjectivePGP also provides pre-built frameworks for direct integration: - [ObjectivePGP.framework](Frameworks/) - [ObjectivePGP.xcframework](Frameworks/) ### Response N/A ``` -------------------------------- ### Install ObjectivePGP via Package Managers Source: https://github.com/krzyzanowskim/objectivepgp/blob/main/Frameworks/iphoneos/ObjectivePGP.xcframework/README.md Provides configuration snippets for integrating ObjectivePGP into projects using Swift Package Manager or CocoaPods. ```swift dependencies: [ .package(url: "https://github.com/krzyzanowskim/ObjectivePGP.git", .upToNextMinor(from: "0.17.0")) ] ``` ```ruby pod 'ObjectigePGP' ``` -------------------------------- ### ObjectivePGP Keyring Management Source: https://github.com/krzyzanowskim/objectivepgp/blob/main/README.md Examples of creating, importing, deleting, and finding keys within a PGP keyring in Objective-C and Swift. ```objective-c PGPKeyring *keyring = ObjectivePGP.defaultKeyring; PGPKeyring *keyring = [[PGPKeyring alloc] init]; NSArray *allKeys = keyring.keys; [keyring importKeys:@[key]]; [keyring deleteKeys:@[key]]; [keyring importKey:@"979E4B03DFFE30C6" fromPath:@"/path/to/secring.gpg"]; PGPKey *key = [keyring findKeyWithIdentifier:@"979E4B03DFFE30C6"]; NSArray keys = [pgp findKeysForUserID:@"Name "]; ``` ```swift 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 ").forEach { // process key } ``` -------------------------------- ### Swift Package Manager Installation for ObjectivePGP Source: https://github.com/krzyzanowskim/objectivepgp/blob/main/Frameworks/iphonesimulator/ObjectivePGP.xcframework/README.md Provides instructions for adding ObjectivePGP to your Swift project using the Swift Package Manager. This involves specifying the repository URL and version constraints in your Package.swift file. ```swift dependencies: [ .package(url: "https://github.com/krzyzanowskim/ObjectivePGP.git", .upToNextMinor(from: "0.17.0")) ] ``` -------------------------------- ### CocoaPods Installation for ObjectivePGP Source: https://github.com/krzyzanowskim/objectivepgp/blob/main/Frameworks/iphonesimulator/ObjectivePGP.xcframework/README.md Details how to integrate ObjectivePGP into your Objective-C or Swift project using CocoaPods. This is achieved by adding the 'ObjectigePGP' pod to your Podfile. ```ruby pod 'ObjectigePGP' ``` -------------------------------- ### Manage PGP Keyrings Source: https://github.com/krzyzanowskim/objectivepgp/blob/main/Frameworks/iphonesimulator/ObjectivePGP.xcframework/README.md Demonstrates how to initialize a keyring, import/delete keys, and search for keys by identifier or user ID. ```objective-c PGPKeyring *keyring = ObjectivePGP.defaultKeyring; PGPKeyring *keyring = [[PGPKeyring alloc] init]; NSArray *allKeys = keyring.keys; [keyring importKeys:@[key]]; [keyring deleteKeys:@[key]]; [keyring importKey:@"979E4B03DFFE30C6" fromPath:@"/path/to/secring.gpg"]; PGPKey *key = [keyring findKeyWithIdentifier:@"979E4B03DFFE30C6"]; NSArray keys = [pgp findKeysForUserID:@"Name "]; ``` ```swift 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") { } keyring.findKeys("Name ").forEach(key) { } ``` -------------------------------- ### Load PGP Keys from File or Data Source: https://context7.com/krzyzanowskim/objectivepgp/llms.txt Demonstrates how to read public or private PGP keys from a file path or raw data. The framework automatically detects between binary and ASCII-armored formats. ```swift import ObjectivePGP do { let keys = try ObjectivePGP.readKeys(fromPath: "/path/to/keyring.gpg") for key in keys { print("Key ID: \(key.keyID.longIdentifier)") print("Is Secret: \(key.isSecret)") print("Is Public: \(key.isPublic)") print("Expiration: \(String(describing: key.expirationDate))") } } catch { print("Failed to read keys: \(error)") } let keyData = try Data(contentsOf: URL(fileURLWithPath: "/path/to/key.asc")) if let keys = try? ObjectivePGP.readKeys(from: keyData) { print("Loaded \(keys.count) keys from data") } ``` ```objective-c #import NSError *error; NSArray *keys = [ObjectivePGP readKeysFromPath:@"/path/to/keyring.gpg" error:&error]; if (error) { NSLog(@"Failed to read keys: %@", error); } else { for (PGPKey *key in keys) { NSLog(@"Key ID: %@", key.keyID.longIdentifier); NSLog(@"Is Secret: %d", key.isSecret); } } NSData *keyData = [NSData dataWithContentsOfFile:@"/path/to/key.asc"]; NSArray *loadedKeys = [ObjectivePGP readKeysFromData:keyData error:&error]; ``` -------------------------------- ### Manage PGP Keyring Source: https://github.com/krzyzanowskim/objectivepgp/blob/main/Frameworks/macos/ObjectivePGP.xcframework/Versions/A/Resources/README.md Demonstrates how to interact with a PGP keyring, including accessing default or creating new keyrings, importing, deleting, and finding keys by identifier or user ID. ```Objective-C PGPKeyring *keyring = ObjectivePGP.defaultKeyring; PGPKeyring *keyring = [[PGPKeyring alloc] init]; NSArray *allKeys = keyring.keys; [keyring importKeys:@[key]]; [keyring deleteKeys:@[key]]; [keyring importKey:@"979E4B03DFFE30C6" fromPath:@"/path/to/secring.gpg"]; PGPKey *key = [keyring findKeyWithIdentifier:@"979E4B03DFFE30C6"]; NSArray keys = [pgp findKeysForUserID:@"Name "]; ``` ```Swift 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 ").forEach { key in // process key } ``` -------------------------------- ### Encrypt & Decrypt Data Source: https://github.com/krzyzanowskim/objectivepgp/blob/main/README.md Demonstrates how to encrypt data with an optional signature and then decrypt it using ObjectivePGP. ```APIDOC ## Encrypt & Decrypt Data ### Description Encrypts data with an optional signature and decrypts it using provided keys. ### Method N/A (These are library function calls) ### Endpoint N/A ### Parameters #### Objective-C - `fileContent` (NSData) - The data to encrypt. - `addSignature` (BOOL) - Whether to add a signature to the encrypted data. - `usingKeys` (NSArray) - An array of keys to use for encryption/decryption. - `passphraseForKey` (NSString) - The passphrase for the secret key, if required. #### Swift - `fileContent` (Data) - The data to encrypt. - `addSignature` (Bool) - Whether to add a signature to the encrypted data. - `using` (Array) - An array of keys to use for encryption/decryption. ### Request Example ```objective-c // Objective-C Example NSData *encrypted = [ObjectivePGP encrypt:fileContent addSignature:YES usingKeys:@[key] passphraseForKey:nil error:nil]; [ObjectivePGP decrypt:encrypted andVerifySignature:YES usingKeys:@[key] passphraseForKey:nil error:nil]; ``` ```swift // Swift Example let encrypted = try ObjectivePGP.encrypt(fileContent, addSignature: true, using: [key1, key2]) let decrypted = try ObjectivePGP.decrypt(encrypted, andVerifySignature: true, using: [key1]) ``` ### Response #### Success Response (200) - `encrypted` (NSData/Data) - The encrypted data. - `decrypted` (NSData/Data) - The decrypted data. #### Response Example ```json { "encrypted": "", "decrypted": "" } ``` ``` -------------------------------- ### Import ObjectivePGP Library Source: https://github.com/krzyzanowskim/objectivepgp/blob/main/Frameworks/macos/ObjectivePGP.xcframework/Versions/A/Resources/README.md Import the ObjectivePGP library for use in Objective-C or Swift projects. ```Objective-C #import ``` ```Swift import ObjectivePGP ``` -------------------------------- ### Manage PGP Key Metadata and User Identities Source: https://context7.com/krzyzanowskim/objectivepgp/llms.txt Demonstrates how to retrieve key identifiers, check key status (secret/public/encrypted), access user IDs, and perform key management operations like adding/removing identities and decryption. ```swift import ObjectivePGP let keys = try ObjectivePGP.readKeys(fromPath: "/path/to/key.gpg") let key = keys.first! // Key identifiers print("Long Key ID: \(key.keyID.longIdentifier)") print("Short Key ID: \(key.keyID.shortIdentifier)") // Key type checks print("Has Secret Key: \(key.isSecret)") print("Has Public Key: \(key.isPublic)") print("Is Encrypted: \(key.isEncryptedWithPassword)") // Expiration if let expiration = key.expirationDate { print("Expires: \(expiration)") } else { print("Key does not expire") } // Access partial keys if let publicKey = key.publicKey { print("Public key fingerprint: \(publicKey.fingerprint.description)") print("Public key type: \(publicKey.type)") // Access users for user in publicKey.users { print("User ID: \(user.userID)") if let image = user.image { print("User has image: \(image.count) bytes") } } // Primary user if let primaryUser = publicKey.primaryUser { print("Primary user: \(primaryUser.userID)") } // Subkeys for subkey in publicKey.subKeys { print("Subkey ID: \(subkey.keyID.longIdentifier)") } } // Add a new User ID to the key key.addUserId("New Identity ", passphraseForKey: { _ in return "keyPassphrase" }) // Remove a User ID key.removeUserId("Old Identity ") // Decrypt a password-protected key do { let decryptedKey = try key.decrypted(withPassphrase: "keyPassphrase") print("Key decrypted successfully") } catch { print("Failed to decrypt key: \(error)") } ``` ```objective-c #import NSArray *keys = [ObjectivePGP readKeysFromPath:@"/path/to/key.gpg" error:nil]; PGPKey *key = keys.firstObject; // Key identifiers NSLog(@"Long Key ID: %@", key.keyID.longIdentifier); NSLog(@"Short Key ID: %@", key.keyID.shortIdentifier); // Key properties NSLog(@"Has Secret Key: %d", key.isSecret); NSLog(@"Has Public Key: %d", key.isPublic); NSLog(@"Is Encrypted: %d", key.isEncryptedWithPassword); // Expiration if (key.expirationDate) { NSLog(@"Expires: %@", key.expirationDate); } // Access users for (PGPUser *user in key.publicKey.users) { NSLog(@"User ID: %@", user.userID); } // Add User ID [key addUserId:@"New Identity " passphraseForKey:^NSString * _Nullable(PGPKey * _Nonnull key) { return @"keyPassphrase"; }]; // Remove User ID [key removeUserId:@"Old Identity "]; // Decrypt key NSError *error; PGPKey *decryptedKey = [key decryptedWithPassphrase:@"keyPassphrase" error:&error]; ``` -------------------------------- ### ASCII Armor Encoding/Decoding with ObjectivePGP Source: https://github.com/krzyzanowskim/objectivepgp/blob/main/Frameworks/iphonesimulator/ObjectivePGP.xcframework/README.md Illustrates how to use the PGPArmor class to convert binary PGP data into ASCII armored format, suitable for transmission via standard text-based protocols like email. It covers public keys, secret keys, and encrypted/decrypted messages. ```objective-c NSString *armoredKey = [PGPArmor armoredData:encrypted as:PGPArmorPublicKey]; ``` ```swift let armoredKey = Armor.armored(Data(), as: .publicKey) ``` -------------------------------- ### Handle PGP Decryption Errors and Passphrase Callbacks Source: https://context7.com/krzyzanowskim/objectivepgp/llms.txt Demonstrates how to catch and handle specific PGP error codes during decryption and how to provide passphrases dynamically using a callback mechanism. ```swift import ObjectivePGP do { let decrypted = try ObjectivePGP.decrypt(encryptedData, andVerifySignature: true, using: keys, passphraseForKey: nil) } catch let error as NSError { switch error.code { case 5: print("A passphrase is required to decrypt the key") case 6: print("The provided passphrase is incorrect") case 7: print("Signature is invalid or cannot be verified") case 8: print("The message is not signed") case 9: print("Invalid or corrupted PGP message") case 10: print("Expected signature is missing") case 11: print("Required key or data not found") default: print("Error: \(error.localizedDescription)") } } let decrypted = try ObjectivePGP.decrypt(encryptedData, andVerifySignature: false, using: keys, passphraseForKey: { key in guard let key = key else { return nil } if key.keyID.longIdentifier == "71180E514EF122E5" { return "passphrase1" } else if key.keyID.longIdentifier == "ABC123DEF456" { return "passphrase2" } return nil }) ``` ```objective-c #import NSError *error; NSData *decrypted = [ObjectivePGP decrypt:encryptedData andVerifySignature:YES usingKeys:keys passphraseForKey:nil error:&error]; if (error) { switch (error.code) { case PGPErrorPassphraseRequired: NSLog(@"Passphrase required"); break; case PGPErrorPassphraseInvalid: NSLog(@"Invalid passphrase"); break; case PGPErrorInvalidSignature: NSLog(@"Invalid signature"); break; case PGPErrorNotSigned: NSLog(@"Message not signed"); break; case PGPErrorInvalidMessage: NSLog(@"Invalid PGP message"); break; default: NSLog(@"Error: %@", error.localizedDescription); } } ``` -------------------------------- ### Convert PGP Data to ASCII Armor Source: https://context7.com/krzyzanowskim/objectivepgp/llms.txt Demonstrates how to convert binary PGP data such as encrypted messages, public/secret keys, and signatures into ASCII-armored strings for text-based storage or transmission. ```swift let armoredMessage = Armor.armored(encryptedBinary, as: .message) let armoredPublicKey = Armor.armored(publicKeyData, as: .publicKey) let armoredSecretKey = Armor.armored(secretKeyData, as: .secretKey) let armoredSignature = Armor.armored(signatureData, as: .signature) ``` ```objective-c NSString *armoredMessage = [PGPArmor armored:encryptedData as:PGPArmorMessage]; NSString *armoredPublicKey = [PGPArmor armored:publicKeyData as:PGPArmorPublicKey]; NSString *armoredSecretKey = [PGPArmor armored:secretKeyData as:PGPArmorSecretKey]; NSString *armoredSignature = [PGPArmor armored:signatureData as:PGPArmorSignature]; ``` -------------------------------- ### Generate New Key Pair Source: https://github.com/krzyzanowskim/objectivepgp/blob/main/Frameworks/iphoneos/ObjectivePGP.xcframework/README.md Demonstrates how to generate a new PGP public and secret key pair using Objective-C and Swift. ```APIDOC ## Generate New Key Pair ### Description Generates a new PGP key pair for a given email address. ### Method N/A (Code Example) ### Endpoint N/A ### Parameters N/A ### Request Example #### Objective-C ```objective-c PGPKeyGenerator *generator = [[PGPKeyGenerator alloc] init]; PGPKey *key = [generator generateFor:@"Marcin " passphrase:nil]; NSData *publicKeyData = [key export:PGPKeyTypePublic error:nil]; NSData *secretKeyData = [key export:PGPKeyTypeSecret error:nil]; ``` #### Swift ```swift let key = KeyGenerator().generate(for: "marcin@example.com", passphrase: "password") let publicKey = try key.export(keyType: .public) let secretKey = try key.export(keyType: .secret) ``` ### Response N/A ``` -------------------------------- ### Exporting Keys Source: https://context7.com/krzyzanowskim/objectivepgp/llms.txt Export keys from a keyring or individual key objects to binary or ASCII-armored format for storage or sharing. ```APIDOC ## Exporting Keys ### Description Export keys from a keyring or individual key objects to binary or ASCII-armored format for storage or sharing. ### Method N/A (Code examples provided) ### Endpoint N/A (Code examples provided) ### Parameters N/A (Code examples provided) ### Request Example N/A ### Response N/A ## Swift Example ```swift import ObjectivePGP let keyring = ObjectivePGP.defaultKeyring // Export entire keyring to file (binary format) let exportedData = try keyring.export() try exportedData.write(to: URL(fileURLWithPath: "keyring.gpg")) // Export only public keys if let publicKeys = try? keyring.exportKeys(of: .public) { try publicKeys.write(to: URL(fileURLWithPath: "public-keys.gpg")) } // Export only secret keys if let secretKeys = try? keyring.exportKeys(of: .secret) { try secretKeys.write(to: URL(fileURLWithPath: "secret-keys.gpg")) } // Export a single key (armored format) if let key = keyring.findKey("4EF122E5"), let armoredKey = keyring.export(key: key, armored: true) { let armoredString = String(data: armoredKey, encoding: .utf8) print(armoredString ?? "") } // Export key directly from PGPKey object let key = keyring.keys.first! let publicKeyData = try key.export(keyType: .public) let secretKeyData = try key.export(keyType: .secret) ``` ## Objective-C Example ```objectivec #import PGPKeyring *keyring = ObjectivePGP.defaultKeyring; // Export keyring to file NSError *error; NSData *exportedData = [keyring export:&error]; [exportedData writeToURL:[NSURL fileURLWithPath:@"keyring.gpg"] atomically:YES]; // Export public keys only NSData *publicKeys = [keyring exportKeysOfType:PGPKeyTypePublic error:&error]; // Export single key (armored) PGPKey *key = [keyring findKeyWithIdentifier:@"4EF122E5"]; NSData *armoredKey = [keyring exportKey:key armored:YES]; // Export from PGPKey object directly NSData *publicKeyData = [key export:PGPKeyTypePublic error:&error]; NSData *secretKeyData = [key export:PGPKeyTypeSecret error:&error]; ``` ``` -------------------------------- ### ASCII Armor Encoding Source: https://github.com/krzyzanowskim/objectivepgp/blob/main/Frameworks/iphoneos/ObjectivePGP.xcframework/README.md Explains and demonstrates how to use ASCII armor to encode binary PGP data into a text format suitable for email or other standard messaging systems. ```APIDOC ## ASCII Armor Encoding ### Description Encodes binary PGP data into ASCII armor format for transmission via standard text-based protocols like email. Provides a cheatsheet for correct `PGPArmorType` usage. ### Method N/A (Code Example) ### Endpoint N/A ### Parameters N/A ### Request Example #### Objective-C ```objective-c NSString *armoredKey = [PGPArmor armoredData:encrypted as:PGPArmorPublicKey]; ``` #### Swift ```swift let armoredKey = Armor.armored(Data(), as: .publicKey) ``` ### Response N/A ### Cheatsheet for PGPArmorType | 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)` | *Note: For any result of encryption, the type is `PGPArmorMessage`.* ``` -------------------------------- ### Sign Data with ObjectivePGP Source: https://context7.com/krzyzanowskim/objectivepgp/llms.txt Create digital signatures for data using a private key. Supports both detached signatures (separate from data) and attached signatures (combined with data). Requires ObjectivePGP library and access to private keys. ```swift import ObjectivePGP // Load signing key (private/secret key) let signingKeys = try ObjectivePGP.readKeys(fromPath: "/path/to/private-key.gpg") let dataToSign = "Important document content".data(using: .utf8)! // Create detached signature (signature only, separate from data) let detachedSignature = try ObjectivePGP.sign(dataToSign, detached: true, using: signingKeys, passphraseForKey: { key in return "keyPassphrase" }) // Save signature to file try detachedSignature.write(to: URL(fileURLWithPath: "document.sig")) // Create attached signature (data + signature combined in PGP format) let signedData = try ObjectivePGP.sign(dataToSign, detached: false, using: signingKeys, passphraseForKey: { key in return "keyPassphrase" }) // Save signed data try signedData.write(to: URL(fileURLWithPath: "document.gpg")) // Sign with multiple keys let key1 = try ObjectivePGP.readKeys(fromPath: "/path/to/key1.gpg") let key2 = try ObjectivePGP.readKeys(fromPath: "/path/to/key2.gpg") let multiKeys = key1 + key2 let multiSigned = try ObjectivePGP.sign(dataToSign, detached: true, using: multiKeys, passphraseForKey: { key in // Return appropriate passphrase for each key if key.keyID.longIdentifier == "ABC123" { return "passphrase1" } return "passphrase2" }) ``` ```objective-c #import // Load signing key NSArray *signingKeys = [ObjectivePGP readKeysFromPath:@"/path/to/private-key.gpg" error:nil]; NSData *dataToSign = [@"Important document content" dataUsingEncoding:NSUTF8StringEncoding]; // Create detached signature NSError *error; NSData *signature = [ObjectivePGP sign:dataToSign detached:YES usingKeys:signingKeys passphraseForKey:^NSString * _Nullable(PGPKey * _Nonnull key) { return @"keyPassphrase"; } error:&error]; // Create attached signature NSData *signedData = [ObjectivePGP sign:dataToSign detached:NO usingKeys:signingKeys passphraseForKey:^NSString * _Nullable(PGPKey * _Nonnull key) { return @"keyPassphrase"; } error:&error]; ``` -------------------------------- ### Reading PGP Keys Source: https://context7.com/krzyzanowskim/objectivepgp/llms.txt Load PGP keys (public or private) from a file path or raw data. The framework automatically detects both binary and ASCII-armored key formats. ```APIDOC ## Reading PGP Keys from File or Data ### Description Load PGP keys (public or private) from a file path or raw data. The framework automatically detects both binary and ASCII-armored key formats. ### Method ObjectivePGP.readKeys(fromPath:) ObjectivePGP.readKeys(from:) ObjectivePGP.readKeysFromPath: ObjectivePGP.readKeysFromData: ### Endpoint N/A (Framework methods) ### Parameters #### Path Parameters - **fromPath** (String) - Required - The file path to the PGP key file. #### Query Parameters N/A #### Request Body - **from** (Data) - Required - The raw data containing PGP keys. ### Request Example ```swift import ObjectivePGP // Read keys from file path do { let keys = try ObjectivePGP.readKeys(fromPath: "/path/to/keyring.gpg") for key in keys { print("Key ID: \(key.keyID.longIdentifier)") print("Is Secret: \(key.isSecret)") print("Is Public: \(key.isPublic)") print("Expiration: \(String(describing: key.expirationDate))") } } catch { print("Failed to read keys: \(error)") } // Read keys from Data let keyData = try Data(contentsOf: URL(fileURLWithPath: "/path/to/key.asc")) if let keys = try? ObjectivePGP.readKeys(from: keyData) { print("Loaded \(keys.count) keys from data") } ``` ```objective-c #import // Read keys from file path NSError *error; NSArray *keys = [ObjectivePGP readKeysFromPath:@"/path/to/keyring.gpg" error:&error]; if (error) { NSLog(@"Failed to read keys: %@", error); } else { for (PGPKey *key in keys) { NSLog(@"Key ID: %@", key.keyID.longIdentifier); NSLog(@"Is Secret: %d", key.isSecret); } } // Read keys from NSData NSData *keyData = [NSData dataWithContentsOfFile:@"/path/to/key.asc"]; NSArray *loadedKeys = [ObjectivePGP readKeysFromData:keyData error:&error]; ``` ### Response #### Success Response (200) - **keys** (Array) - An array of PGPKey objects loaded from the provided source. #### Response Example ```json [ { "keyID": { "longIdentifier": "979E4B03DFFE30C6", "shortIdentifier": "DFFE30C6" }, "isSecret": true, "isPublic": false, "expirationDate": null } ] ``` ``` -------------------------------- ### Manage PGP Keyring Operations Source: https://context7.com/krzyzanowskim/objectivepgp/llms.txt Covers the Keyring class for in-memory storage, including importing, searching by identifier or user ID, and deleting keys. ```swift import ObjectivePGP let keyring = ObjectivePGP.defaultKeyring let customKeyring = Keyring() let keys = try ObjectivePGP.readKeys(fromPath: "/path/to/keys.gpg") keyring.import(keys: keys) try keyring.import(keyIdentifier: "979E4B03DFFE30C6", fromPath: "/path/to/secring.gpg") if let key = keyring.findKey("4EF122E5") { print("Found key: \(key.keyID.longIdentifier)") } let userKeys = keyring.findKeys("John Doe ") for key in userKeys { print("User key: \(key.keyID.shortIdentifier)") } let allKeys = keyring.keys print("Total keys in keyring: \(allKeys.count)") keyring.delete(keys: [keys.first!]) keyring.deleteAll() ``` ```objective-c #import PGPKeyring *keyring = ObjectivePGP.defaultKeyring; NSArray *keys = [ObjectivePGP readKeysFromPath:@"/path/to/keys.gpg" error:nil]; [keyring importKeys:keys]; NSError *error; [keyring importKey:@"979E4B03DFFE30C6" fromPath:@"/path/to/secring.gpg" error:&error]; PGPKey *key = [keyring findKeyWithIdentifier:@"71180E514EF122E5"]; NSArray *userKeys = [keyring findKeysForUserID:@"Name "]; [keyring deleteKeys:@[key]]; ``` -------------------------------- ### Export PGP Keys Source: https://context7.com/krzyzanowskim/objectivepgp/llms.txt Export PGP keys from a keyring or individual key objects to binary or ASCII-armored format. This is useful for backing up keys or sharing them with others. The code demonstrates exporting the entire keyring, public keys only, secret keys only, and individual keys. ```swift import ObjectivePGP let keyring = ObjectivePGP.defaultKeyring // Export entire keyring to file (binary format) let exportedData = try keyring.export() try exportedData.write(to: URL(fileURLWithPath: "keyring.gpg")) // Export only public keys if let publicKeys = try? keyring.exportKeys(of: .public) { try publicKeys.write(to: URL(fileURLWithPath: "public-keys.gpg")) } // Export only secret keys if let secretKeys = try? keyring.exportKeys(of: .secret) { try secretKeys.write(to: URL(fileURLWithPath: "secret-keys.gpg")) } // Export a single key (armored format) if let key = keyring.findKey("4EF122E5"), let armoredKey = keyring.export(key: key, armored: true) { let armoredString = String(data: armoredKey, encoding: .utf8) print(armoredString ?? "") } // Export key directly from PGPKey object let key = keyring.keys.first! let publicKeyData = try key.export(keyType: .public) let secretKeyData = try key.export(keyType: .secret) ``` ```objective-c #import PGPKeyring *keyring = ObjectivePGP.defaultKeyring; // Export keyring to file NSError *error; NSData *exportedData = [keyring export:&error]; [exportedData writeToURL:[NSURL fileURLWithPath:@"keyring.gpg"] atomically:YES]; // Export public keys only NSData *publicKeys = [keyring exportKeysOfType:PGPKeyTypePublic error:&error]; // Export single key (armored) PGPKey *key = [keyring findKeyWithIdentifier:@"4EF122E5"]; NSData *armoredKey = [keyring exportKey:key armored:YES]; // Export from PGPKey object directly NSData *publicKeyData = [key export:PGPKeyTypePublic error:&error]; NSData *secretKeyData = [key export:PGPKeyTypeSecret error:&error]; ``` -------------------------------- ### Sign and Verify Data Source: https://github.com/krzyzanowskim/objectivepgp/blob/main/Frameworks/iphonesimulator/ObjectivePGP.xcframework/README.md Signs data using a PGP key and verifies the signature against the original content. ```objective-c NSData *signature = [ObjectivePGP sign:fileContent detached:YES usingKeys:@[key] passphraseForKey:nil error:nil]; [ObjectivePGP verify:fileContent withSignature:signature usingKeys:@[key] passphraseForKey:nil error:nil]; ``` ```swift let signature = try ObjectivePGP.sign(encryptedBin, detached:true, using: [key1]) try ObjectivePGP.verify(encryptedBin, withSignature: signature, using: [key1]) ``` -------------------------------- ### ObjectivePGP Armor Conversion Source: https://context7.com/krzyzanowskim/objectivepgp/llms.txt Methods for encoding binary PGP data into ASCII armor and decoding armored strings back into binary format. ```APIDOC ## Armor.armored(data, as: type) ### Description Converts binary PGP data into an ASCII-armored string format. ### Parameters - **data** (Data) - Required - The binary PGP data to be armored. - **as** (ArmorType) - Required - The type of PGP block (e.g., .message, .publicKey, .secretKey, .signature, .multipartMessagePartXOfY). ### Request Example let armoredMessage = Armor.armored(encryptedBinary, as: .message) ### Response - **String** - The ASCII-armored PGP block string. --- ## Armor.readArmored(string) ### Description Parses an ASCII-armored string and returns the original binary PGP data. ### Parameters - **string** (String) - Required - The ASCII-armored PGP string. ### Request Example let binaryData = try Armor.readArmored(armoredString) ### Response - **Data** - The decoded binary PGP data. --- ## Armor.isArmoredData(data) ### Description Checks if the provided data is in an ASCII-armored format. ### Parameters - **data** (Data) - Required - The data to inspect. ### Response - **Bool** - Returns true if the data is ASCII armored, false otherwise. ``` -------------------------------- ### Generate PGP Key Pair in Objective-C and Swift Source: https://github.com/krzyzanowskim/objectivepgp/blob/main/Frameworks/iphonesimulator/ObjectivePGP.xcframework/README.md Demonstrates how to generate a new PGP public and secret key pair using ObjectivePGP. This process involves initializing a key generator and exporting the generated keys into NSData or Data objects. ```objective-c PGPKeyGenerator *generator = [[PGPKeyGenerator alloc] init]; PGPKey *key = [generator generateFor:@"Marcin " passphrase:nil]; NSData *publicKeyData = [key export:PGPKeyTypePublic error:nil]; NSData *secretKeyData = [key export:PGPKeyTypeSecret error:nil]; ``` ```swift let key = KeyGenerator().generate(for: "marcin@example.com", passphrase: "password") let publicKey = try key.export(keyType: .public) let secretKey = try key.export(keyType: .secret) ``` -------------------------------- ### Read and Validate ASCII Armored Data Source: https://context7.com/krzyzanowskim/objectivepgp/llms.txt Shows how to parse an ASCII-armored string back into binary data and verify if a given data object is in ASCII-armored format. ```swift if let binaryData = try? Armor.readArmored(armoredString) { // Process binary data } let isArmored = Armor.isArmoredData(someData) ``` ```objective-c NSData *binaryData = [PGPArmor readArmored:armoredString error:&error]; BOOL isArmored = [PGPArmor isArmoredData:someData]; ``` -------------------------------- ### POST /verify Source: https://context7.com/krzyzanowskim/objectivepgp/llms.txt Verifies the authenticity of signed data or a standalone signature using public keys. ```APIDOC ## POST /verify ### Description Verifies a PGP signature against original data or validates an attached signature package. ### Method POST ### Endpoint ObjectivePGP.verify(data, withSignature, usingKeys, passphraseForKey) ### Parameters #### Request Body - **data** (Data) - Required - The original data to verify (or the signed data if attached). - **withSignature** (Data) - Optional - The detached signature data (nil if attached). - **usingKeys** (Array) - Required - The public keys of the signer. ### Request Example ObjectivePGP.verify(originalData, withSignature: signatureData, using: verificationKeys, passphraseForKey: nil) ### Response #### Success Response (200) - **verified** (Bool) - Returns true if the signature is valid. #### Response Example { "verified": true } ``` -------------------------------- ### Verify Signatures with ObjectivePGP Source: https://context7.com/krzyzanowskim/objectivepgp/llms.txt Verify digital signatures using the signer's public key. Supports verification of both detached and attached signatures. Requires ObjectivePGP library and the signer's public keys. ```swift import ObjectivePGP // Load verification key (public key of the signer) let verificationKeys = try ObjectivePGP.readKeys(fromPath: "/path/to/signer-public.gpg") let originalData = "Important document content".data(using: .utf8)! // Verify detached signature let signatureData = try Data(contentsOf: URL(fileURLWithPath: "document.sig")) do { let verified = try ObjectivePGP.verify(originalData, withSignature: signatureData, using: verificationKeys, passphraseForKey: nil) print("Signature is valid!") } catch { print("Signature verification failed: \(error)") } // Verify attached signature (signed data contains both message and signature) let signedData = try Data(contentsOf: URL(fileURLWithPath: "document.gpg")) do { try ObjectivePGP.verify(signedData, withSignature: nil, using: verificationKeys, passphraseForKey: nil) print("Attached signature is valid!") } catch { print("Verification failed: \(error)") } // Verify signature only (check if signed by one of the keys) do { try ObjectivePGP.verifySignature(signatureData, using: verificationKeys, passphraseForKey: nil) print("Signature matches one of the provided keys") } catch { print("Signature does not match any key: \(error)") } ``` ```objective-c #import // Load verification key NSArray *verificationKeys = [ObjectivePGP readKeysFromPath:@"/path/to/signer-public.gpg" error:nil]; NSData *originalData = [@"Important document content" dataUsingEncoding:NSUTF8StringEncoding]; NSData *signatureData = [NSData dataWithContentsOfFile:@"document.sig"]; // Verify detached signature NSError *error; BOOL verified = [ObjectivePGP verify:originalData withSignature:signatureData usingKeys:verificationKeys passphraseForKey:nil error:&error]; if (verified) { NSLog(@"Signature is valid!"); } else { NSLog(@"Verification failed: %@", error); } // Verify attached signature NSData *signedData = [NSData dataWithContentsOfFile:@"document.gpg"]; BOOL attachedVerified = [ObjectivePGP verify:signedData withSignature:nil usingKeys:verificationKeys passphraseForKey:nil error:&error]; ``` -------------------------------- ### Keyring Management API Source: https://context7.com/krzyzanowskim/objectivepgp/llms.txt The Keyring class provides in-memory storage for PGP keys with import, export, search, and deletion capabilities. Use the default shared keyring or create custom instances. ```APIDOC ## Keyring Management ### Description The Keyring class provides in-memory storage for PGP keys with import, export, search, and deletion capabilities. Use the default shared keyring or create custom instances. ### Method ObjectivePGP.defaultKeyring Keyring() Keyring.import(keys:) Keyring.import(keyIdentifier:fromPath:) Keyring.findKey(_:) Keyring.findKeys(_:) Keyring.delete(keys:) Keyring.deleteAll() PGPKeyring.defaultKeyring PGPKeyring.alloc.init PGPKeyring.importKeys: PGPKeyring.importKey:fromPath:error: PGPKeyring.findKeyWithIdentifier: PGPKeyring.findKeysForUserID: PGPKeyring.deleteKeys: ### Endpoint N/A (Framework classes and methods) ### Parameters #### Path Parameters - **fromPath** (String) - Required - The file path to the PGP key file for importing. #### Query Parameters N/A #### Request Body - **keys** (Array) - Required - An array of PGPKey objects to import. - **keyIdentifier** (String) - Required - The identifier of the key to import. - **userID** (String) - Required - The user ID (e.g., email or name) to search for keys. ### Request Example ```swift import ObjectivePGP // Use the default shared keyring let keyring = ObjectivePGP.defaultKeyring // Or create a custom keyring let customKeyring = Keyring() // Import keys into keyring let keys = try ObjectivePGP.readKeys(fromPath: "/path/to/keys.gpg") keyring.import(keys: keys) // Import a specific key by identifier from a file try keyring.import(keyIdentifier: "979E4B03DFFE30C6", fromPath: "/path/to/secring.gpg") // Find key by identifier (short 8 chars or long 16 chars) if let key = keyring.findKey("4EF122E5") { print("Found key: \(key.keyID.longIdentifier)") } // Find keys by user ID (email/name) let userKeys = keyring.findKeys("John Doe ") for key in userKeys { print("User key: \(key.keyID.shortIdentifier)") } // Access all keys in the keyring let allKeys = keyring.keys print("Total keys in keyring: \(allKeys.count)") // Delete specific keys keyring.delete(keys: [keys.first!]) // Delete all keys keyring.deleteAll() ``` ```objective-c #import PGPKeyring *keyring = ObjectivePGP.defaultKeyring; // Import keys NSArray *keys = [ObjectivePGP readKeysFromPath:@"/path/to/keys.gpg" error:nil]; [keyring importKeys:keys]; // Import specific key by identifier NSError *error; [keyring importKey:@"979E4B03DFFE30C6" fromPath:@"/path/to/secring.gpg" error:&error]; // Find key by identifier PGPKey *key = [keyring findKeyWithIdentifier:@"71180E514EF122E5"]; // Find keys by user ID NSArray *userKeys = [keyring findKeysForUserID:@"Name "]; // Delete keys [keyring deleteKeys:@[key]]; ``` ### Response #### Success Response (200) - **keyring** (Keyring/PGPKeyring) - The keyring object, potentially modified by the operation. - **foundKey** (PGPKey) - The PGPKey object found by the identifier. - **foundKeys** (Array) - An array of PGPKey objects matching the user ID. #### Response Example ```json { "status": "success", "message": "Key imported successfully." } ``` ``` -------------------------------- ### Export PGP Keys Source: https://github.com/krzyzanowskim/objectivepgp/blob/main/Frameworks/iphonesimulator/ObjectivePGP.xcframework/README.md Exports keyring data to a file or retrieves public keys as NSData/Data objects. ```objective-c [[keyring export:error] writeToURL:[NSURL fileURLWithString:@"keyring.gpg"]]; NSData *publicKeys = [keyring exportKeysOfType:PGPKeyTypePublic error:nil]; ``` ```swift try keyring.export().write(to: URL(fileURLWithPath: "keyring.gpg")) let publicKeys = keyring.exportKeys(of: .public) ``` -------------------------------- ### PGP Key Metadata and User Management Source: https://context7.com/krzyzanowskim/objectivepgp/llms.txt Methods for accessing key identifiers, checking key status, managing user identities, and decrypting keys. ```APIDOC ## PGP Key Management Operations ### Description Provides access to key metadata, user ID management, and decryption utilities for PGP keys. ### Methods - **readKeysFromPath**: Loads keys from a file path. - **addUserId**: Adds a new identity to the key (requires passphrase if encrypted). - **removeUserId**: Removes an existing identity from the key. - **decryptedWithPassphrase**: Decrypts a password-protected key. ### Key Properties - **keyID** (Object) - Contains long and short identifiers. - **isSecret** (Boolean) - Indicates if the secret key is present. - **isPublic** (Boolean) - Indicates if the public key is present. - **expirationDate** (Date) - The expiration date of the key, if applicable. ### Request Example (Swift) ```swift let keys = try ObjectivePGP.readKeys(fromPath: "/path/to/key.gpg") key.addUserId("New Identity ", passphraseForKey: { _ in return "pass" }) ``` ### Response - **PGPKey** (Object) - The key object containing public/secret components, user list, and subkeys. ### Response Example { "keyID": "A1B2C3D4E5F6G7H8", "isSecret": true, "users": ["User Name "] } ``` -------------------------------- ### Read PGP Keys from File Source: https://github.com/krzyzanowskim/objectivepgp/blob/main/Frameworks/iphonesimulator/ObjectivePGP.xcframework/README.md Reads PGP public or private keys from a specified file path. Returns an array of PGPKey objects or throws an error if the operation fails. ```objective-c NSArray *keys = [ObjectivePGP readKeysFromPath:@"/path/to/key.asc" error:nil]; ``` ```swift let keys = try ObjectivePGP.readKeys(fromPath: "/path/to/key.asc") ```