clr: () => localStorage.clear(),
};
+
+
/*
Cryptographic API
*/
const Crypto = {
api: window.crypto.subtle,
- gen: ()=> Crypto.api.generateKey(
+
+ stoa: (str)=>{
+ const buf = new Uint8Array(new ArrayBuffer(str.length));
+ for (let i = 0; i < str.length; i++) {
+ bufView[i] = str.charCodeAt(i);
+ }
+ return buf;
+ },
+
+ atos: (array)=> String.fromCharCode.apply(null, new Uint8Array(array)),
+
+ generate: ()=> Crypto.api.generateKey(
{
name: "RSA-OAEP",
modulusLength: 4096,
hash: "SHA-256",
},
true,
- ["encrypt", "decrypt"]
+ ["encrypt", "decrypt", "sign", "verify"]
),
+
+ import: (key)=>{
+ const binkey = window.atob(key);
+ const keybuf = Crypto.stoa(binkey);
+ return Crypto.api.importKey(
+ "pkcs8",
+ keybuf,
+ {
+ name: "RSA-OAEP",
+ modulusLength: 4096,
+ publicExponent: new Uint8Array([1, 0, 1]),
+ hash: "SHA-256",
+ },
+ true,
+ ["encrypt", "decrypt", "sign", "verify"]
+ );
+ },
+
+ export: (key)=>{
+ const expkey = await Crypto.api.exportKey("pkcs8", key);
+ const strkey = Crypto.atos(expkey);
+ return window.btoa(strkey);
+ },
}
/*