33 releases

0.7.2 Dec 12, 2022
0.7.1 Oct 11, 2022
0.7.0 Oct 8, 2021
0.6.3 Apr 30, 2021
0.5.11 Jun 20, 2019

#74 in Cryptography

Download history 1632/week @ 2022-10-11 1642/week @ 2022-10-18 2259/week @ 2022-10-25 1794/week @ 2022-11-01 2043/week @ 2022-11-08 2064/week @ 2022-11-15 1697/week @ 2022-11-22 1847/week @ 2022-11-29 2447/week @ 2022-12-06 3021/week @ 2022-12-13 2403/week @ 2022-12-20 2988/week @ 2022-12-27 3362/week @ 2023-01-03 3875/week @ 2023-01-10 4480/week @ 2023-01-17 3862/week @ 2023-01-24

16,475 downloads per month
Used in 20 crates (9 directly)

MIT license

4.5K SLoC

CI status Last version Documentation


A pure Rust implementation of the Minisign signature system.

This is a crate, designed to be used within by applications.

For a command-line tool reimplementing the Minisign utility in Rust, and based on this crate, check out rsign2.

For a minimal crate that to only verify signatures, check out minisign-verify.

API documentation

API documentation on docs.rs


fn main() {
    extern crate minisign;
    use minisign::{KeyPair, PublicKeyBox, SecretKeyBox, SignatureBox};
    use std::io::Cursor;

    // Generate and return a new key pair
    // The key is encrypted using a password.
    // If `None` is given, the password will be asked for interactively.
    let KeyPair { pk, sk } =
        KeyPair::generate_encrypted_keypair(Some("key password".to_string())).unwrap();

    // In order to be stored to disk, keys have to be converted to "boxes".
    // A box is just a container, with some metadata about its content.
    // Boxes can be converted to/from strings, making them convenient to use for storage.
    let pk_box_str = pk.to_box().unwrap().to_string();
    let sk_box_str = sk
        .to_box(None) // Optional comment about the key

    // `pk_box_str` and `sk_box_str` can now be saved to disk.
    // This is a long-term key pair, that can be used to sign as many files as needed.
    // For conveniency, the `KeyPair::generate_and_write_encrypted_keypair()` function
    // is available: it generates a new key pair, and saves it to disk (or any `Writer`)
    // before returning it.

    // Assuming that `sk_box_str` is something we previously saved and just reloaded,
    // it can be converted back to a secret key box:
    let sk_box = SecretKeyBox::from_string(&sk_box_str).unwrap();

    // and the box can be opened using the password to reveal the original secret key:
    let sk = sk_box
        .into_secret_key(Some("key password".to_string()))

    // Now, we can use the secret key to sign anything.
    let data = b"lorem ipsum";
    let data_reader = Cursor::new(data);
    let signature_box = minisign::sign(None, &sk, data_reader, None, None).unwrap();

    // We have a signature! Let's inspect it a little bit.
        "Untrusted comment: [{}]",
        "Trusted comment: [{}]",

    // Converting the signature box to a string in order to save it is easy.
    let signature_box_str = signature_box.into_string();

    // Now, let's verify the signature.
    // Assuming we just loaded it into `signature_box_str`, get the box back.
    let signature_box = SignatureBox::from_string(&signature_box_str).unwrap();

    // Load the public key from the string.
    let pk_box = PublicKeyBox::from_string(&pk_box_str).unwrap();
    let pk = pk_box.into_public_key().unwrap();

    // And verify the data.
    let data_reader = Cursor::new(data);
    let verified = minisign::verify(&pk, &signature_box, data_reader, true, false, false);
    match verified {
        Ok(()) => println!("Success!"),
        Err(_) => println!("Verification failed"),


~14K SLoC