const Cryptr = require("cryptr"); import { readFileSync } from "fs"; import schema from "./models/password"; interface main { encryptionKey: string; encrypter: any; } class main { constructor() { const encryptionKey = readFileSync("./src/key.txt", { encoding: "utf-8" }); this.encrypter = new Cryptr(encryptionKey.toString()); } get(website: string) { schema .findOne({ website: website, }) .then((data) => { if (!data) return console.log("No password found!"); console.log(data.password); console.log(this.encrypter.decrypt(data.password)); process.exit(0); }); } set(password: string, website: string) { const encrypted = this.encrypter.encrypt(password); schema .findOneAndUpdate( { website: website, }, { password: encrypted, }, { upsert: true, } ) .then(() => { console.log("Saved!"); process.exit(0); }); } } export default main;