Skip to main content

Crate herolib_crypt

Crate herolib_crypt 

Source
Expand description

§herolib-crypt

Simple and secure cryptography library for Rust.

This crate provides:

  • Asymmetric cryptography: Ed25519 signing and X25519 encryption
  • Symmetric cryptography: XChaCha20-Poly1305 authenticated encryption

§Quick Start

§Asymmetric Encryption (Public Key)

use herolib_crypt::{generate_keypair, encrypt_message, decrypt_message};

// Generate keypair
let keypair = generate_keypair().unwrap();

// Encrypt for recipient using their encryption public key
let encrypted = encrypt_message("secret", &keypair.encryption_public_key_hex).unwrap();

// Decrypt with private key
let decrypted = decrypt_message(&encrypted, &keypair.encryption_private_key_hex).unwrap();
assert_eq!(decrypted, "secret");

§Symmetric Encryption (Shared Key)

use herolib_crypt::symmetric::{EncryptionKey, Cipher};

// Generate a random key
let key = EncryptionKey::generate();
let cipher = Cipher::new(key);

// Encrypt and decrypt
let encrypted = cipher.encrypt(b"secret data").unwrap();
let decrypted = cipher.decrypt(&encrypted).unwrap();
assert_eq!(decrypted, b"secret data");

Re-exports§

pub use asymmetric::CryptoError;
pub use asymmetric::CryptoResult;
pub use asymmetric::KeyPair;
pub use asymmetric::decrypt_message;
pub use asymmetric::encrypt_message;
pub use asymmetric::encryption_public_key_from_private;
pub use asymmetric::generate_keypair;
pub use asymmetric::public_key_from_private;
pub use asymmetric::sign_message;
pub use asymmetric::verify_signature;

Modules§

asymmetric
httpsig
HeroLib HTTP Signatures
keys
HeroLib Keys
symmetric
Cryptographic primitives for data-at-rest encryption using XChaCha20-Poly1305.