#key-pair #rsa-key #rsa #crypto #back-end #decryption #crytography

srsa

A simple backend for creating and using RSA key pairs. Intended for personal use.

8 releases

0.1.7 Apr 30, 2023
0.1.6 Apr 15, 2023

#1718 in Cryptography

MIT license

11KB
168 lines

srsa

A simple backend for creating and using RSA key pairs using the rsa crate.

This is meant to be plug and play and I plan to plug this in as a backend for other ideas I have in mind. This is also my first time doing anything crytography related and as such the choices I make may not be the best. Feel free to submit a PR or issue for any ideas or improvements you have.

Usage

A crate that uses the already well established rsa and pkcs8 crates to provide a simple plug and play experience.


lib.rs:

A crate that uses the already well established rsa and pkcs8 crates to provide a simple plug and play experience.

Usage

Saving key pairs

use srsa::Keys;
use anyhow::Result as AnyResult;

fn main() -> AnyResult<()> {
    // The values passed in will be the file names of the private and public keys.
    let keys = Keys::new("priv", "pub");

    // Saves the key pairs to a folder in the cwd called keys and encrypts the private key with a
    // password
    keys.write_to_disk("password", "keys")?;

    Ok(())
}

Using an existing key pair

use srsa::Keys;
use anyhow::Result as AnyResult;

fn main() -> AnyResult<()> {
    let keys = Keys::retrieve_keys("keys/test_priv", "1234", "keys/test_pub")?;
    let ciphertext = keys.seal(b"hi")?;
    let plaintext = keys.unseal(&ciphertext)?;
    Ok(())
}

Encrypting and decrypt things work very similarly.

  1. You retrieve the neccessary keys to do the job.
  2. You run the appropriate function. The encryption function called seal, the decryption function is called unseal.

Dependencies

~5MB
~105K SLoC