1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import { Component } from "@angular/core";
- import { NavController, ToastController } from "ionic-angular";
- import { Storage } from "@ionic/storage";
- import { CryptoProvider } from "../../providers/crypto/crypto";
- @Component({
- selector: "page-settings",
- templateUrl: "settings.html"
- })
- export class SettingsPage {
- keywords: string;
- privateKey: string;
- publicKey: string;
- constructor(
- public navCtrl: NavController,
- public toastCtrl: ToastController,
- private cryptoUtils: CryptoProvider,
- private storage: Storage
- ) {
- this.loadValuesFromStorage();
- }
- async loadValuesFromStorage() {
- this.privateKey = await this.storage.get("privateKey");
- this.publicKey = await this.storage.get("publicKey");
- this.keywords = await this.storage.get("keywords");
- }
- async generateKeys() {
- const keys = await this.cryptoUtils.generateRsaKeys();
- this.publicKey = await this.cryptoUtils.extractPublicKey(keys);
- this.privateKey = await this.cryptoUtils.extractPrivateKey(keys);
- }
- save() {
- this.storage.set("publicKey", this.publicKey);
- this.storage.set("privateKey", this.privateKey);
- this.storage.set("keywords", this.keywords);
- const toast = this.toastCtrl.create({
- message: "Successfully saved!",
- position: "bottom",
- duration: 3000
- });
- toast.present();
- }
- publishPublicKey() {
- this.cryptoUtils.publishPublicKey(this.publicKey);
- }
- }
|