summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--encrypt_key.js9
-rw-r--r--genkey.html26
2 files changed, 35 insertions, 0 deletions
diff --git a/encrypt_key.js b/encrypt_key.js
new file mode 100644
index 0000000..2a36177
--- /dev/null
+++ b/encrypt_key.js
@@ -0,0 +1,9 @@
+function encrypt_private_key(password, private_key) {
+ let public_key = private_key.substring(64,128);
+ let priv = sodium.from_hex(private_key.substring(0,64));
+ if (password.length > 0) {
+ for (i=0; i<priv.length; i++)
+ priv[i] ^= password[i % password.length].charCodeAt(0);
+ }
+ return sodium.to_hex(priv) + public_key;
+}
diff --git a/genkey.html b/genkey.html
new file mode 100644
index 0000000..b73f21a
--- /dev/null
+++ b/genkey.html
@@ -0,0 +1,26 @@
+<html>
+<head>
+ <script src="/encrypt_key.js"></script>
+ <script>
+ window.sodium = {
+ onload: function (sodium) {
+ var sodium = sodium;
+ update();
+ }
+ };
+ function update() {
+ let password = document.getElementById("password").value;
+ let key = sodium.crypto_sign_keypair('hex');
+ encryptedPrivateKey = encrypt_private_key(password, key.privateKey);
+ document.getElementById("output").innerHTML =
+ '$privKey = "' + encryptedPrivateKey + '";<br>' +
+ '$pubKey = "' + key.publicKey + '";';
+ }
+ </script>
+ <script src="/sodium.js" async></script>
+</head>
+<body>
+<input type="password" id="password" onchange="update();" onkeypress="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();">
+<p id="output"></p>
+</body>
+</html>