Expand description
Sign and verify using RSA or ED25519 with a focus on simplicity.
Use a simple interface: sign
or verify
,
from either the ed or rsa modules supporting multiple key formats.
To sign:
- Get the key bytes using
PrivateKey::<type>(..source..).read()
- Optionally, cache these bytes for reuse
- Use
sign
To verify:
- Get the key bytes using
PublicKey::<type>(..source..).read()
- Optionally, cache these bytes for reuse
- Use
verify
Here’s a full sign-verify cycle using ED25519
, with keys generated using OpenSSL in this way:
ⓘ
$ openssl genpkey -algorithm ED25519 -out ed.private.pem
$ openssl pkey -in private-key-ed.pem -pubout -out ed.public.pem
Sign and verify using sharpie::ed:
ⓘ
use std::fs;
use base64::{prelude::BASE64_STANDARD, Engine};
use sharpie::ed::{sign, verify, PrivateKey, PublicKey};
fn main() -> anyhow::Result<()> {
let privkey = PrivateKey::PEM(fs::read_to_string("sharpie/fixtures/ed.private.pem")?).read()?;
let sig = sign(b"hello world", &privkey)?;
let pubkey = PublicKey::PEM(fs::read_to_string("sharpie/fixtures/ed.public.pem")?).read()?;
verify(b"hello world", &sig, &pubkey)?;
println!(
"Verified ed25519 signature, base64 encoded:\n{}",
BASE64_STANDARD.encode(sig)
);
Ok(())
}