mirror of
https://github.com/freedit-org/freedit.git
synced 2026-01-10 04:58:07 -05:00
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
(function () {
|
|
var publicKeyText = document.getElementById("public-key-text");
|
|
var privateKeyText = document.getElementById("private-key-text");
|
|
var privateKeyDownload = document.getElementById("private-key-download");
|
|
var button = document.getElementById("button");
|
|
var message = document.getElementById("message");
|
|
var result = document.getElementById("result");
|
|
|
|
var success = function (keys) {
|
|
publicKeyText.value = arrayBufferToPem(
|
|
keys.publicKeyBuffer,
|
|
"RSA PUBLIC KEY",
|
|
);
|
|
privateKeyText.value = arrayBufferToPem(
|
|
keys.privateKeyBuffer,
|
|
"RSA PRIVATE KEY",
|
|
);
|
|
privateKeyDownload.href = window.URL.createObjectURL(
|
|
new Blob([privateKeyText.value], { type: "application/octet-stream" }),
|
|
);
|
|
result.style.display = "block";
|
|
message.innerText = null;
|
|
button.disabled = false;
|
|
};
|
|
|
|
var error = function (error) {
|
|
message.innerText = error;
|
|
button.disabled = false;
|
|
};
|
|
|
|
var process = function () {
|
|
message.innerText = "Processing...";
|
|
button.disabled = true;
|
|
generateRsaKeys().then(success, error);
|
|
};
|
|
|
|
var warn = function () {
|
|
if (privateKey.value === "") return;
|
|
return "Are you sure? Your keys will be lost unless you've saved them.";
|
|
};
|
|
|
|
button.addEventListener("click", process);
|
|
window.onbeforeunload = warn;
|
|
})();
|