https://github.com/zonblade/aes-256-gcm-rs
Implementation of aes-gcm create, focusing only on aes 256 with some additional features
https://github.com/zonblade/aes-256-gcm-rs
aes-256 aes-encryption aes-gcm rust-lang
Last synced: 8 months ago
JSON representation
Implementation of aes-gcm create, focusing only on aes 256 with some additional features
- Host: GitHub
- URL: https://github.com/zonblade/aes-256-gcm-rs
- Owner: zonblade
- License: mit
- Created: 2024-03-27T06:51:47.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-16T07:47:41.000Z (over 1 year ago)
- Last Synced: 2025-02-25T10:13:43.714Z (8 months ago)
- Topics: aes-256, aes-encryption, aes-gcm, rust-lang
- Language: Rust
- Homepage: https://crates.io/crates/aes-256-gcm
- Size: 13.7 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AES 256 GCM with Enhancement
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:
- Allowed Encrypted Data
- Returned Data
- Initialization
- Options
- Decrypting
- Error Coverage
- Usage Recommendation---
#### Allowed data consumption
any data that can implement serde::Serialize
#### Returned data
any data that can implement serde::Deserialize
---
#### Initialization :: Using OS ENV
```rust
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);
}
```#### Initialization :: Using Custom Secret
```rust
use aes_256_gcm::Client;fn main(){
let my_secret:&str = "some of my secret";
let aes_client = Client::new(my_secret);
}
```#### Options :: Normal without expiration
```rust
let result: Result = client.encrypt(
"something or struct", None
);
```#### Options :: With Expiration "Second"
```rust
let result: Result = client.encrypt(
"something or struct",
AesOptions::with_expire_second(3)
.build()
);
```#### Options :: With Expiration "chrono Date"
```rust
// let's just pretend this few days ahead
let date_expired = chrono::Utc::now();
// use it with 'with_expire_date'
let result: Result = client.encrypt(
"something or struct",
AesOptions::with_expire_date(date_expired)
.build()
);
```#### Decrypting
`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
```rust
let result: Result = client.decrypt::(&token);
```
#### Usage Recommendation
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](https://github.com/zonblade/aes-256-gcm-rs/example)\
> i'm opening to anyone want to contribute either example or crate improvement.