Crates.io | gaia-crypt |
lib.rs | gaia-crypt |
version | |
source | src |
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 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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.