| Crates.io | gaia-crypt |
| lib.rs | gaia-crypt |
| version | 0.1.0 |
| created_at | 2025-03-15 00:16:40.814241+00 |
| updated_at | 2025-03-15 00:16:40.814241+00 |
| description | A cryptographic library for secure communication in the GaiaNet ecosystem |
| homepage | |
| repository | https://github.com/GaiaNet-AI/gaia-crypt |
| max_upload_size | |
| id | 1592882 |
| size | 28,364 |
A hybrid encryption library in Rust that provides secure RSA + AES-GCM encryption and decryption functionality.
gaia-crypt implements a modern hybrid cryptographic system that combines:
This approach leverages the strengths of both algorithms: RSA's security for key exchange and AES's performance for bulk data encryption.
Add this to your Cargo.toml:
[dependencies]
gaia-crypt = "0.1.0"
use gaia_crypt::generate_rsa_keypair;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let (private_key, public_key) = generate_rsa_keypair()?;
// Keys can be converted to PEM strings for storage/transmission
let private_key_pem = private_key.to_pkcs1_pem()?;
let public_key_pem = public_key.to_public_key_pem()?;
println!("Generated RSA key pair successfully");
Ok(())
}
use gaia_crypt::{encrypt, decrypt};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// In a real application, you would load these from secure storage
let public_key_pem = "-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----";
let private_key_pem = "-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----";
// Data to encrypt
let data = b"This is a secret message";
// Encrypt using the recipient's public key
let encrypted_data = encrypt(public_key_pem, data)?;
println!("Encrypted data size: {} bytes", encrypted_data.len());
// Decrypt using the recipient's private key
let decrypted_data = decrypt(private_key_pem, &encrypted_data)?;
assert_eq!(data, &decrypted_data[..]);
println!("Successfully decrypted: {}", String::from_utf8_lossy(&decrypted_data));
Ok(())
}
Encryption Process:
Decryption Process:
This approach securely encrypts data of arbitrary size while maintaining performance.