Crate sharpie

Source
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:

  1. Get the key bytes using PrivateKey::<type>(..source..).read()
  2. Optionally, cache these bytes for reuse
  3. Use sign

To verify:

  1. Get the key bytes using PublicKey::<type>(..source..).read()
  2. Optionally, cache these bytes for reuse
  3. 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(())
}

Modules§

ed
ED25519 signing and verification
rsa
RSA signing and verification

Enums§

Error