decryption: always request key passphrase based on key ID
This commit is contained in:
parent
d136175d93
commit
2ae751044c
6 changed files with 85 additions and 130 deletions
|
|
@ -70,7 +70,7 @@ struct GopenPGPInterface: PGPInterface {
|
|||
privateKeys.keys.contains { key in key.hasSuffix(keyID.lowercased()) }
|
||||
}
|
||||
|
||||
func decrypt(encryptedData: Data, keyID: String?, passphrase: String) throws -> Data? {
|
||||
func decrypt(encryptedData: Data, keyID: String?, passPhraseForKey: @escaping (String) -> String) throws -> Data? {
|
||||
let key: CryptoKey? = {
|
||||
if let keyID {
|
||||
return privateKeys.first(where: { key, _ in key.hasSuffix(keyID.lowercased()) })?.value
|
||||
|
|
@ -87,6 +87,7 @@ struct GopenPGPInterface: PGPInterface {
|
|||
try privateKey.isLocked(&isLocked)
|
||||
var unlockedKey: CryptoKey!
|
||||
if isLocked.boolValue {
|
||||
let passphrase = passPhraseForKey(privateKey.getFingerprint())
|
||||
unlockedKey = try privateKey.unlock(passphrase.data(using: .utf8))
|
||||
} else {
|
||||
unlockedKey = privateKey
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue