|
@@ -25,6 +25,13 @@ export class SettingsPage {
|
|
|
this.keywords = await this.storage.get("keywords");
|
|
|
}
|
|
|
|
|
|
+ async generateKeys() {
|
|
|
+ const keys = await this.generateRsaKeys();
|
|
|
+
|
|
|
+ this.publicKey = await this.extractPublicKey(keys);
|
|
|
+ this.privateKey = await this.extractPrivateKey(keys);
|
|
|
+ }
|
|
|
+
|
|
|
save() {
|
|
|
this.storage.set("publicKey", this.publicKey);
|
|
|
this.storage.set("privateKey", this.privateKey);
|
|
@@ -37,4 +44,35 @@ export class SettingsPage {
|
|
|
});
|
|
|
toast.present();
|
|
|
}
|
|
|
+
|
|
|
+ private async generateRsaKeys() {
|
|
|
+ return await crypto.subtle.generateKey(
|
|
|
+ {
|
|
|
+ name: "RSA-OAEP",
|
|
|
+ modulusLength: 1024,
|
|
|
+ publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
|
|
|
+ hash: { name: "SHA-256" }
|
|
|
+ },
|
|
|
+ true,
|
|
|
+ ["encrypt", "decrypt"]
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ private async extractPrivateKey(keys): Promise<string> {
|
|
|
+ return btoa(
|
|
|
+ String.fromCharCode.apply(
|
|
|
+ null,
|
|
|
+ new Uint8Array(await crypto.subtle.exportKey("pkcs8", keys.privateKey))
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ private async extractPublicKey(keys): Promise<string> {
|
|
|
+ return btoa(
|
|
|
+ String.fromCharCode.apply(
|
|
|
+ null,
|
|
|
+ new Uint8Array(await crypto.subtle.exportKey("spki", keys.publicKey))
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|