refactor PasswordEntitiy model, add decrypt extension

This commit is contained in:
Bob Sun 2017-02-02 18:02:43 +08:00
parent a2b3d450ba
commit d44aec6527
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
4 changed files with 51 additions and 25 deletions

View file

@ -16,23 +16,7 @@ class PasswordDetailViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let encryptedDataURL = URL(fileURLWithPath: "\(Globals.shared.documentPath)/\(passwordEntity!.rawPath!)")
let fm = FileManager.default
if fm.fileExists(atPath: encryptedDataURL.path){
print("file exist")
} else {
print("file doesnt exist")
}
do {
let encryptedData = try Data(contentsOf: encryptedDataURL)
let decryptedData = try PasswordStore.shared.pgp.decryptData(encryptedData, passphrase: Defaults[.pgpKeyPassphrase])
let plain = String(data: decryptedData, encoding: .ascii) ?? ""
print(plain)
passwordTextView.text = plain
} catch let error as NSError {
print(error.debugDescription)
}
let password = passwordEntity!.decrypt()!
passwordTextView.text = password.password
}
}