use keychain to store pgp passphrase and git password
This commit is contained in:
parent
ceb52a5b33
commit
90709675a3
10 changed files with 86 additions and 19 deletions
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
import Foundation
|
||||
import SwiftyUserDefaults
|
||||
import KeychainAccess
|
||||
import UIKit
|
||||
|
||||
class Utils {
|
||||
|
|
@ -70,6 +71,37 @@ class Utils {
|
|||
Defaults.remove(.pgpPublicKeyURL)
|
||||
Defaults.remove(.pgpKeyID)
|
||||
}
|
||||
|
||||
static func getPasswordFromKeychain(name: String) -> String? {
|
||||
let keychain = Keychain(service: "me.mssun.passforios")
|
||||
do {
|
||||
return try keychain.getString(name)
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
static func addPasswrodToKeychain(name: String, password: String) {
|
||||
let keychain = Keychain(service: "me.mssun.passforios")
|
||||
keychain[name] = password
|
||||
}
|
||||
static func removeKeychain(name: String) {
|
||||
let keychain = Keychain(service: "me.mssun.passforios")
|
||||
do {
|
||||
try keychain.remove(name)
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
static func removeAllKeychain() {
|
||||
let keychain = Keychain(service: "me.mssun.passforios")
|
||||
do {
|
||||
try keychain.removeAll()
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://gist.github.com/NikolaiRuhe/eeb135d20c84a7097516
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue