a
This commit is contained in:
22
encrypt.html
22
encrypt.html
@@ -19,21 +19,25 @@
|
||||
// put keys in backtick (``) to avoid errors caused by spaces or tabs
|
||||
const pubkey = document.getElementById("pubKey").value
|
||||
|
||||
const options = {
|
||||
let options;
|
||||
try {
|
||||
options = {
|
||||
message: openpgp.message.fromText(document.getElementById("text").value), // input as Message object
|
||||
publicKeys: (await openpgp.key.readArmored(pubkey)).keys, // for encryption
|
||||
}
|
||||
} catch (err) {
|
||||
document.getElementById("result").value = err.message;
|
||||
document.getElementById("progressbar").className = "progress-bar bg-danger";
|
||||
}
|
||||
|
||||
openpgp.encrypt(options).then(ciphertext => {
|
||||
encrypted = ciphertext.data // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
|
||||
if (encrypted) {
|
||||
document.getElementById("result").value = encrypted;
|
||||
document.getElementById("progressbar").className = "progress-bar bg-success";
|
||||
} else {
|
||||
document.getElementById("result").value = 'Encryption failed.';
|
||||
document.getElementById("progressbar").className = "progress-bar bg-danger";
|
||||
}
|
||||
})
|
||||
document.getElementById("result").value = encrypted;
|
||||
document.getElementById("progressbar").className = "progress-bar bg-success";
|
||||
}).catch(function(error){
|
||||
document.getElementById("result").value = error.message;
|
||||
document.getElementById("progressbar").className = "progress-bar bg-danger";
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
|
||||
Reference in New Issue
Block a user