Expand description
§mytheclipse-crypto
Low-level security helpers that are easy to get wrong when hand-rolled:
- Argon2id password hashing & verification (
passwordfeature), with RFC 9106-ish parameters. - AES-256-GCM authenticated encryption with a fresh random nonce per
operation (
encryptionfeature). - JWT (HS256) / Paseto v4 local token generation & validation (
tokensfeature). - 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§
- Crypto
Error - Errors returned across mytheclipse-crypto primitives.