summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2023-05-16 13:20:02 +0200
committerErich Eckner <git@eckner.net>2023-05-16 14:35:19 +0200
commitd6b68b7988fad876380e31816a113d7b3ba8ee02 (patch)
tree52fe2a56adbdf6787c9e8e2d0f339b0afec3192b
parenta04faeeccdaeb7582ea096e436624bbaafbe39ab (diff)
downloadmocp-web-d6b68b7988fad876380e31816a113d7b3ba8ee02.tar.xz
genkey neu
-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>