forked from krzyzanowskim/ObjectivePGP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Contents.swift
24 lines (18 loc) · 931 Bytes
/
Contents.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Build ObjectivePGP target first.
import ObjectivePGP
import Foundation
// Generate new key
let key1 = KeyGenerator().generate(for: "[email protected]", passphrase: nil)
let key2 = KeyGenerator().generate(for: "[email protected]", passphrase: nil)
let plaintext = Data(bytes: [1,2,3,4,5])
// Encrypt 5 bytes using selected key
let encryptedBin = try ObjectivePGP.encrypt(plaintext, addSignature: false, using: [key1, key2])
let encrypted = Armor.armored(encryptedBin, as: .message)
print(encrypted)
// Sign the encrypted binary
let signatureBin = try ObjectivePGP.sign(encryptedBin, detached: true, using: [key1])
let signature = Armor.armored(signatureBin, as: .signature)
print(signature)
try ObjectivePGP.verify(encryptedBin, withSignature: signatureBin, using: [key1])
let decrypted = try ObjectivePGP.decrypt(encryptedBin, andVerifySignature: false, using: [key1])
print("Decrypted : \(Array(decrypted))")