
O ObjectivePGP é uma implementação do protocolo OpenPGP para iOS e macOS. OpenPGP é o padrão de criptografia de email mais utilizado. É definido pelo grupo de trabalho OpenPGP da Força -Tarefa de Engenharia da Internet (IETF).
Aqui está a história da postagem do blog.
Você quer ajudar, ótimo! Vá em frente e pegue nosso repositório, faça suas alterações e envie -nos uma solicitação de tração.
Você pode contribuir. Consulte Contribuindo.md
Crie solicitação de puxar.
O ObjectivePGP permanece sob uma licença dupla:
Grátis para uso não comercial, coberto pela variante da licença BSD. Isso significa que você precisa mencionar Marcin Krzyżanowski como o autor original deste código e reproduzir o texto da licença dentro do seu aplicativo.
Licença de uso comercial para usar em produtos comerciais. Lembre -se de que alguns produtos gratuitos permanecem produtos comerciais. Entre em contato comigo por e -mail para obter detalhes.
Não tem certeza do que escolher? Verifique FAQ
dependencies: [
.package(url: "https://github.com/krzyzanowskim/ObjectivePGP.git", .upToNextMinor(from: "0.99.4"))
]
pod 'ObjectivePGP'
O ObjectivePGP vem com as estruturas para o lançamento mais recente, você pode copiar e incorporar seu projeto:
Objective-C
# import < ObjectivePGP/ObjectivePGP.h >Swift
import ObjectivePGP NSArray <PGPKey *> *keys = [ObjectivePGP readKeysFromPath: @" /path/to/key.asc " error: nil ]; let keys = try ObjectivePGP . readKeys ( fromPath : " /path/to/key.asc " ) O Keyring é um armazenamento (na memória ou no disco) que mantém todos os tipos de teclas 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 ) Assine os dados com uma chave:
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 ) A ASCII Armour é um conversor de codificação binário para textual. A ASCII Armour envolve a envolvimento de mensagens criptografadas no ASCII, para que possam ser enviadas em um formato de mensagens padrão, como email.
Exemplo:
-----BEGIN PGP PUBLIC KEY BLOCK-----
Comment: For more info see https://www.objectivepgp.org
[...]
-----END PGP PUBLIC KEY BLOCK-----
PGPArmor de classe pode ser usado para converter formato binário em formato ASCII
NSString *armoredKey = [PGPArmor armoredData: encrypted as: PGPArmorPublicKey]; let armoredKey = Armor . armored ( Data ( ) , as : . publicKey ) Quando convertem manualmente, é importante usar o valor correto PGPArmorType que define o cabeçalho. Pode ser uma parte complicada, então aqui está a folha de trapaceiros:
| Dados de tipo | PgParmortype | Exemplo |
|---|---|---|
| Criptografado | PGPArmorMessage | Armor.armored(ObjectivePGP.encrypt(...), as: .message) |
| Descriptografado | PGPArmorMessage | Armor.armored(ObjectivePGP.decrypt(...), as: .message) |
| Chave pública | PGPArmorTypePublic | Armor.armored(key.export(), as: .publicKey) |
| Chave secreta | PGPArmorTypeSecret | Armor.armored(key.export(), as: .secretKey) |
Para qualquer resultado da criptografia, o tipo é PGPArmorMessage
Veja Changelog
Limitações conhecidas:
Até o momento, a base do código ObjectivePGP passou por uma auditoria de segurança completa do CURE53.
Este produto usa o software desenvolvido pelo projeto OpenSSL para uso no OpenSSL Toolkit. (http://www.openssl.org/)
Marcin Krzyżanowski