
ObjectivePGP เป็นการดำเนินการของโปรโตคอล OpenPGP สำหรับ iOS และ MACOS OpenPGP เป็นมาตรฐานการเข้ารหัสอีเมลที่ใช้กันอย่างแพร่หลาย มันถูกกำหนดโดยคณะทำงาน OpenPGP ของ Internet Engineering Task Force (IETF)
นี่คือบล็อกโพสต์
คุณต้องการความช่วยเหลือเยี่ยมมาก! ไปข้างหน้าและแยก repo ของเราทำการเปลี่ยนแปลงของคุณและส่งคำขอดึงมาให้เรา
คุณยินดีที่จะมีส่วนร่วม ดูการสนับสนุน. md
โปรดสร้างคำขอดึง
ObjectivePGP อยู่ภายใต้ใบอนุญาตคู่:
ฟรีสำหรับการใช้งานที่ไม่ใช่เชิงพาณิชย์ครอบคลุมโดยตัวแปรของใบอนุญาต BSD นั่นหมายความว่าคุณต้องพูดถึง Marcin Krzyżanowskiในฐานะผู้เขียนต้นฉบับของรหัสนี้และทำซ้ำข้อความใบอนุญาตภายในแอปของคุณ
ใบอนุญาตการใช้งานเชิงพาณิชย์เพื่อใช้ในผลิตภัณฑ์เชิงพาณิชย์ โปรดทราบว่าผลิตภัณฑ์ฟรีบางอย่างยังคงเป็นผลิตภัณฑ์เชิงพาณิชย์ กรุณาติดต่อฉันทางอีเมลสำหรับรายละเอียด
ไม่แน่ใจว่าจะเลือกอะไร? ตรวจสอบคำถามที่พบบ่อย
dependencies: [
.package(url: "https://github.com/krzyzanowskim/ObjectivePGP.git", .upToNextMinor(from: "0.99.4"))
]
pod 'ObjectivePGP'
ObjectivePGP มาพร้อมกับเฟรมเวิร์กสำหรับรุ่นล่าสุดคุณสามารถคัดลอกและฝังในโครงการของคุณ:
วัตถุประสงค์ -C
# import < ObjectivePGP/ObjectivePGP.h >ฉับพลัน
import ObjectivePGP NSArray <PGPKey *> *keys = [ObjectivePGP readKeysFromPath: @" /path/to/key.asc " error: nil ]; let keys = try ObjectivePGP . readKeys ( fromPath : " /path/to/key.asc " ) Keyring เป็นที่เก็บข้อมูล (ในหน่วยความจำหรือบนดิสก์) ที่เก็บคีย์ PGP ทุกประเภท
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 protected]> " ]; 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 protected]> " ) . forEach ( key ) {
// process key
} // 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 ) ลงชื่อเข้าใช้ข้อมูลด้วยคีย์:
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 ] ) 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 ] ) PGPKeyGenerator *generator = [[PGPKeyGenerator alloc ] init ];
PGPKey *key = [generator generateFor: @" Marcin <[email protected]> " passphrase: nil ];
NSData *publicKeyData = [key export: PGPKeyTypePublic error: nil ];
NSData *secretKeyData = [key export: PGPKeyTypeSecret error: nil ]; let key = KeyGenerator ( ) . generate ( for : " [email protected] " , passphrase : " password " )
let publicKey = try key . export ( keyType : . public )
let secretKey = try key . export ( keyType : . secret ) ASCII Armour เป็นตัวแปลงการเข้ารหัสแบบไบนารีเป็นข้อความ ชุดเกราะ ASCII เกี่ยวข้องกับการเข้ารหัสการส่งข้อความที่เข้ารหัสใน ASCII เพื่อให้สามารถส่งในรูปแบบการส่งข้อความมาตรฐานเช่นอีเมล
ตัวอย่าง:
-----BEGIN PGP PUBLIC KEY BLOCK-----
Comment: For more info see https://www.objectivepgp.org
[...]
-----END PGP PUBLIC KEY BLOCK-----
คลาส PGPArmor สามารถใช้ในการแปลงรูปแบบไบนารีเป็นรูปแบบ ASCII
NSString *armoredKey = [PGPArmor armoredData: encrypted as: PGPArmorPublicKey]; let armoredKey = Armor . armored ( Data ( ) , as : . publicKey ) เมื่อแปลงด้วยตนเองเป็นสิ่งสำคัญที่จะต้องใช้ค่า PGPArmorType ที่ถูกต้องซึ่งกำหนดส่วนหัว อาจเป็นส่วนที่ยุ่งยากดังนั้นนี่คือ Cheatsheet:
| พิมพ์ข้อมูล | PGPARMORTYPE | ตัวอย่าง |
|---|---|---|
| ที่ได้เข้ารหัส | PGPArmorMessage | Armor.armored(ObjectivePGP.encrypt(...), as: .message) |
| ถอดออก | PGPArmorMessage | Armor.armored(ObjectivePGP.decrypt(...), as: .message) |
| คีย์สาธารณะ | PGPArmorTypePublic | Armor.armored(key.export(), as: .publicKey) |
| คีย์ลับ | PGPArmorTypeSecret | Armor.armored(key.export(), as: .secretKey) |
สำหรับผลลัพธ์ของการเข้ารหัสประเภทคือ PGPArmorMessage
ดู Changelog
ข้อ จำกัด ที่รู้จัก:
ในวันที่ฐานรหัส ObjectivePGP ได้รับการตรวจสอบความปลอดภัยที่สมบูรณ์จาก CURE53
ผลิตภัณฑ์นี้ใช้ซอฟต์แวร์ที่พัฒนาโดยโครงการ OpenSSL สำหรับใช้ในชุดเครื่องมือ OpenSSL (http://www.openssl.org/)
Marcin Krzyżanowski