|
@@ -28,10 +28,10 @@ export class SettingsPage {
|
|
|
}
|
|
|
|
|
|
async generateKeys() {
|
|
|
- const keys = await this.generateRsaKeys();
|
|
|
+ const keys = await this.cryptoUtils.generateRsaKeys();
|
|
|
|
|
|
- this.publicKey = await this.extractPublicKey(keys);
|
|
|
- this.privateKey = await this.extractPrivateKey(keys);
|
|
|
+ this.publicKey = await this.cryptoUtils.extractPublicKey(keys);
|
|
|
+ this.privateKey = await this.cryptoUtils.extractPrivateKey(keys);
|
|
|
}
|
|
|
|
|
|
save() {
|
|
@@ -50,35 +50,4 @@ export class SettingsPage {
|
|
|
publishPublicKey() {
|
|
|
this.cryptoUtils.publishPublicKey(this.publicKey);
|
|
|
}
|
|
|
-
|
|
|
- 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))
|
|
|
- )
|
|
|
- );
|
|
|
- }
|
|
|
}
|