#crypto #sha

crypto-utils

Cryptography Utils for Rust

5 releases (3 breaking)

Uses new Rust 2021

0.4.1 Sep 16, 2022
0.4.0 Jun 29, 2022
0.3.0 Jun 23, 2022
0.2.0 Jun 11, 2022
0.1.0 Jun 11, 2022

#3 in #sha

Download history 157/week @ 2022-06-11 142/week @ 2022-06-18 77/week @ 2022-06-25 56/week @ 2022-07-02 47/week @ 2022-07-09 29/week @ 2022-07-16 46/week @ 2022-07-23 26/week @ 2022-07-30 26/week @ 2022-08-06 33/week @ 2022-08-13 25/week @ 2022-08-20 23/week @ 2022-08-27 5/week @ 2022-09-03 78/week @ 2022-09-10 100/week @ 2022-09-17

213 downloads per month

MIT license

24KB
228 lines

Cryptography Utils for Rust

github crates-io docs-rs ci

Cryptography Utils for Rust

Importing

The driver is available on crates.io. To use the driver in your application, simply add it to your project's Cargo.toml.

[dependencies]
crypto-utils = "0.4.1"

How to use?

Compute a Sha hash

Quick and easy Sha1, Sha256 and Sha512 hash computing.

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<u8>

// decode hash to a String
let hash = hex::encode(hash_bytes); // String

assert_eq!(hash, "21bd12dc183f740ee76f27b78eb39c8ad972a757".to_string())

Json Web Token

Create and decode a token

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

Dependencies

~0.2–3MB
~69K SLoC