rusty_crypt
A simple and secure Rust library providing an easy-to-use interface for AES-256-GCM authenticated encryption.
rusty_crypt provides high-level utilities to easily integrate modern symmetric encryption into Rust applications.
Features
- 🔐 AES-256-GCM authenticated encryption
- 🔑 Secure AES-256 key generation
- 🎲 Secure nonce generation
- 📦 Text encryption and decryption
- 📁 Binary data encryption and decryption
- ⚠️ Safe error handling with
Result<T, CryptoError> - 🚫 No panic-based cryptographic failures
Installation
Add rusty_crypt to your Cargo.toml:
[]
= "0.3.2"
Overview
rusty_crypt uses the AES-256-GCM algorithm.
AES-GCM provides:
-
Confidentiality
Data is encrypted and cannot be read without the key. -
Integrity
Any modification of encrypted data is detected. -
Authentication
Invalid keys or corrupted ciphertext are rejected during decryption.
AES-256 requires a:
32 bytes key (256 bits)
AES-GCM uses a:
12 bytes nonce (96 bits)
A unique nonce must be generated for every encryption operation.
Quick Start
Encrypt and decrypt text
use ;
use ;
Encrypt binary data
rusty_crypt can encrypt any binary data:
- Files
- Images
- Documents
- Network payloads
- Serialized data
Example:
use ;
Key generation
Generate a secure AES-256 key:
use AesGeneratedKey;
Output:
Key size: 32 bytes
Nonce generation
Generate a secure AES-GCM nonce:
use AesGcmGeneratedNonce;
Output:
Nonce size: 12 bytes
Error handling
All cryptographic operations return:
The library does not panic when an encryption or decryption error occurs.
Available errors:
- Invalid Base64
- Invalid AES key size
- Invalid nonce size
- Invalid ciphertext format
- Encryption failure
- Decryption failure
- Invalid UTF-8 data
- Random generation failure
Example:
use AesGcmDecrypt;
Security recommendations
For secure applications:
- Never reuse an AES-GCM nonce with the same key.
- Never expose encryption keys.
- Store keys securely.
- Do not hardcode keys inside your source code.
- Use a secure key management system for production.
rusty_crypt provides low-level cryptographic primitives.
Documentation
Full API documentation:
License
MIT License