Skip to main content

Crate mytheclipse_crypto

Crate mytheclipse_crypto 

Source
Expand description

§mytheclipse-crypto

Low-level security helpers that are easy to get wrong when hand-rolled:

  • Argon2id password hashing & verification (password feature), with RFC 9106-ish parameters.
  • AES-256-GCM authenticated encryption with a fresh random nonce per operation (encryption feature).
  • JWT (HS256) / Paseto v4 local token generation & validation (tokens feature).
  • Key rotation via KeyRing: decryption/verification tries the current key then a list of previous keys.

Nothing in the crate owns long-lived key material; keys are passed in as bytes/keys by the caller and the caller is responsible for storage. Each primitive is small enough to reason about in one screen.

§Example

use mytheclipse_crypto::{PasswordHasher, Encryptor, TokenSigner};

// Hash & verify a password.
let hasher = PasswordHasher::new();
let hash = hasher.hash("hunter2").unwrap();
assert!(hasher.verify(&hash, "hunter2"));

// Encrypt & decrypt a blob.
let key = [0u8; 32];
let enc = Encryptor::new(&key);
let (nonce, ct) = enc.encrypt(b"secret message");
let plain = enc.decrypt(&nonce, &ct).unwrap();
assert_eq!(plain, b"secret message");

// Sign & verify a JWT.
let signer = TokenSigner::new("super-secret-key");
let token = signer
    .sign(&serde_json::json!({ "sub": "u1" }), std::time::Duration::from_secs(3600))
    .unwrap();
let claims = signer.verify(&token).unwrap();
assert_eq!(claims["sub"], "u1");

Re-exports§

pub use password::PasswordHasher;
pub use encryption::AeadError;
pub use encryption::Encryptor;
pub use token::Claims;
pub use token::TokenError;
pub use token::TokenSigner;
pub use key_registry::TypedKeyRegistry;
pub use key_ring::KeyRing;

Modules§

encryption
AES-256-GCM authenticated encryption with a random nonce per operation.
key_registry
Typed key registry with ID-based lookup (feature password).
key_ring
Key rotation support.
password
Argon2id password hashing (RFC 9106).
token
JWT (HS256) generation and validation.

Enums§

CryptoError
Errors returned across mytheclipse-crypto primitives.

Constants§

KEY_LEN
The fixed AES-256-GCM key length in bytes.
NONCE_LEN
The fixed AES-256-GCM nonce length (96 bits) in bytes.