Demo🔗
Enter a message below and then press the encrypt button. The encrypted message will appear at the bottom. Optionally you can change the recipient of the message, by substituting a different public key.
Module Loading, please wait...
Public Key (optional)
The current public key defaults to mine. You can change the recipient just be replacing my public key with theirs.
Your encrypted message will appear here.
The encrypted message can then be copied and sent, e.g. via email, to the intended recipient. They will be the only one that can read it.
I made this mini-project because practically every online PGP implementations broke for my public key. While I have no idea why, they all seemed to use OpenPGP.js, so maybe there's some underlying problem there with the defaults being used.
For this I used rust (Sequoia-PGP), compiled to wasm, and just wired it up to a simple UI as you see here. You can view the repo, but the code more or less looks as follows:
use std::io::Write;
use sequoia_openpgp::{policy::StandardPolicy, serialize::stream::{Armorer, Encryptor2, LiteralWriter, Message}, Cert};
use wasm_bindgen::prelude::*;
use sequoia_openpgp::parse::Parse;
#[wasm_bindgen]
pub fn encrypt_message(public_key: &str, msg_str: &str) -> Result<String, JsValue> {
let cert = Cert::from_bytes(public_key).expect("Trouble parsing cert");
let p = &StandardPolicy::new();
let recipients =
cert.keys().with_policy(p, None).supported().alive().revoked(false)
.for_transport_encryption();
let mut sink = vec![];
let message = Message::new(&mut sink);
let message = Armorer::new(message).build().expect("Trouble armoring message");
let message = Encryptor2::for_recipients(message, recipients).build().expect("encryptor 2");
let mut w = LiteralWriter::new(message).build().expect("Trouble creating writer from message");
let _ = w.write_all(msg_str.as_bytes());
let _ = w.finalize();
let result = String::from_utf8(sink).expect("Trouble converting result to string");
return Ok(result);
}
Leave a Comment:
Comments: (0)
👋🏼