Crates.io | aes-256-gcm |
lib.rs | aes-256-gcm |
version | 1.1.2 |
source | src |
created_at | 2024-03-27 15:30:01.724935 |
updated_at | 2024-03-29 12:51:19.602381 |
description | Implementation of AES-GCM (Aes 256 Gcm) with some enhancement |
homepage | |
repository | https://github.com/zonblade/aes-256-gcm-rs |
max_upload_size | |
id | 1188121 |
size | 17,049 |
Inspired by simplicity of (let's say JWT) this crate provide high-level abstraction for AES-GCM Crate with some enhancement such as expiration check
notes : if you want to use os environment for "SINGLE" key management, you can use
AES_GCM_SECRET
env key
WARNING : IN PRODUCTION DO NOT LEAVE SECRET EMPTY, AVOID AT ANY COSTS
WARNING : THIS CRATE DOES NOT IMPLEMENT "SIV"
Content:
any data that can implement serde::Serialize
any data that can implement serde::Deserialize
use aes_256_gcm::Client;
fn main(){
// this will consume AES_GCM_SECRET
// if no env found it would set to default empty
let aes_client = Client::new(None);
}
use aes_256_gcm::Client;
fn main(){
let my_secret:&str = "some of my secret";
let aes_client = Client::new(my_secret);
}
let result: Result<String, AesError> = client.encrypt(
"something or struct", None
);
let result: Result<String, AesError> = client.encrypt(
"something or struct",
AesOptions::with_expire_second(3)
.build()
);
// let's just pretend this few days ahead
let date_expired = chrono::Utc::now();
// use it with 'with_expire_date'
let result: Result<String, AesError> = client.encrypt(
"something or struct",
AesOptions::with_expire_date(date_expired)
.build()
);
YourDataType
can be String
or struct
or anything,
make sure it is the same data type with encryption,
otherwise it wont decrypting.
side notes : don't forget to check their expiration :D
let result: Result<YourDataType, AesError> = client.decrypt::<YourDataType>(&token);
for usage it's better to know well about Arc
or around Mutex
,
and how data being shared across thread. If your application shared with multiple
thread or async it's better to do best-practice of data sharing.
if you're integrating to some kind of framework, try to understand how their data sharing works.
for other example please visit example
i'm opening to anyone want to contribute either example or crate improvement.