Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/m3dzik/rust-crypto-utils
Cryptography Utils for Rust
https://github.com/m3dzik/rust-crypto-utils
crypto crypto-library cryptography hash hmac jsonwebtoken jwt rust rust-crate rust-lang rust-language rustlang
Last synced: 15 days ago
JSON representation
Cryptography Utils for Rust
- Host: GitHub
- URL: https://github.com/m3dzik/rust-crypto-utils
- Owner: M3DZIK
- License: mit
- Created: 2022-06-11T10:41:57.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-26T23:10:40.000Z (almost 2 years ago)
- Last Synced: 2024-10-30T18:09:38.883Z (17 days ago)
- Topics: crypto, crypto-library, cryptography, hash, hmac, jsonwebtoken, jwt, rust, rust-crate, rust-lang, rust-language, rustlang
- Language: Rust
- Homepage: https://crates.io/crates/crypto-utils
- Size: 79.1 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cryptography Utils for Rust
[![github]](https://github.com/MedzikUser/rust-crypto-utils)
[![crates-io]](https://crates.io/crates/crypto-utils)
[![docs-rs]](https://docs.rs/crypto-utils)
[![ci]](https://github.com/MedzikUser/rust-crypto-utils/actions/workflows/rust.yml)[github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
[crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
[docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs
[ci]: https://img.shields.io/github/workflow/status/MedzikUser/rust-crypto-utils/Rust/main?style=for-the-badge&logo=githubCryptography Utils for Rust
### Importing
The driver is available on [crates.io](https://crates.io/crates/crypto-utils). To use the driver in
your application, simply add it to your project's `Cargo.toml`.```toml
[dependencies]
crypto-utils = "0.4.1"
```### How to use?
#### Compute a Sha hash
Quick and easy Sha1, Sha256 and Sha512 hash computing.
```rust
use crypto_utils::sha::{Algorithm, CryptographicHash};// input data for a hasher
let input = "P@ssw0rd"; // &str// compute hash
let hash_bytes = CryptographicHash::hash(Algorithm::SHA1, input.as_bytes()); // Vec// decode hash to a String
let hash = hex::encode(hash_bytes); // Stringassert_eq!(hash, "21bd12dc183f740ee76f27b78eb39c8ad972a757".to_string())
```#### Json Web Token
Create and decode a token
```rust
use crypto_utils::jsonwebtoken::{Claims, Token};let secret = b"secret";
let user_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";let claims = Claims::new(user_id, 24);
let token = Token::new(secret, claims).unwrap();let decoded = Token::decode(secret, token.encoded).unwrap();
```### All Feature flags
| Feature | Description | Dependencies | Default |
|:-----------|:-------------------------------------------------------------|:-------------------------------------------|:--------|
| `sha` | Enable support for the Sha1, Sha256 and Sha512 hasher | `sha` and `sha2` | yes |
| `jwt` | Enable support for the Json Web Token utils | `chrono`, `serde` and `jsonwebtoken` | yes |License: MIT