aboutsummaryrefslogtreecommitdiffhomepage
path: root/resources/assets/js/initial_key_gen.js
diff options
context:
space:
mode:
Diffstat (limited to 'resources/assets/js/initial_key_gen.js')
-rw-r--r--resources/assets/js/initial_key_gen.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/resources/assets/js/initial_key_gen.js b/resources/assets/js/initial_key_gen.js
new file mode 100644
index 0000000..1b6875f
--- /dev/null
+++ b/resources/assets/js/initial_key_gen.js
@@ -0,0 +1,30 @@
+$('form[keygen]').submit((event) => {
+ event.preventDefault();
+
+ $('button[type="submit"]').attr("disabled", true).html('Loading...');
+
+ var openpgp = window.openpgp;
+
+ var options = {
+ userIds: [{
+ email: $("input#email").val()
+ }],
+ numBits: 4096,
+ passphrase: $("input#password").val()
+ };
+
+ openpgp.generateKey(options).then((key) => {
+ var privateKey = key.privateKeyArmored;
+ var publicKey = key.publicKeyArmored;
+
+ localStorage.setItem("privkey", privateKey);
+
+ var now = new Date();
+ var time = now.getTime();
+ time += 3600 * 1000;
+ now.setTime(time);
+ document.cookie = "publickey=" + encodeURI(publicKey.substr(96).slice(0, -35)) + "; expires=" + now.toUTCString() + ";";
+
+ $('form[keygen]').unbind('submit').submit();
+ });
+}); \ No newline at end of file