40 lines
1.2 KiB
Swift
40 lines
1.2 KiB
Swift
//
|
|
// PasswordDetailViewController.swift
|
|
// pass
|
|
//
|
|
// Created by Mingshen Sun on 18/1/2017.
|
|
// Copyright © 2017 Bob Sun. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import SwiftyUserDefaults
|
|
|
|
class PasswordDetailViewController: UIViewController {
|
|
|
|
@IBOutlet weak var passwordLabel: UILabel!
|
|
var passwordEntity: PasswordEntity?
|
|
|
|
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()
|
|
}
|
|
}
|