passforios/pass/PasswordDetailViewController.swift

41 lines
1.2 KiB
Swift
Raw Normal View History

2017-01-19 21:15:47 +08:00
//
// PasswordDetailViewController.swift
// pass
//
// Created by Mingshen Sun on 18/1/2017.
// Copyright © 2017 Bob Sun. All rights reserved.
//
import UIKit
import SwiftyUserDefaults
2017-01-19 21:15:47 +08:00
class PasswordDetailViewController: UIViewController {
@IBOutlet weak var passwordLabel: UILabel!
var passwordEntity: PasswordEntity?
2017-01-19 21:15:47 +08:00
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)
passwordLabel.text = plain
} catch let error as NSError {
print(error.debugDescription)
}
passwordLabel.sizeToFit()
2017-01-19 21:15:47 +08:00
}
}