Cryptography Utils for Rust
Go to file
renovate[bot] 6a27732f4d fix(deps): update rust crate serde to 1.0.138 2022-07-02 11:35:45 +00:00
.github/workflows ci: update 2022-06-14 20:18:35 +02:00
examples chore(examples): add hmac in sha example 2022-06-29 17:58:33 +02:00
src chore(release): v0.4.0 2022-06-29 15:21:55 +02:00
.gitignore chore: add examples 2022-06-18 11:24:03 +02:00
CHANGELOG.md chore(changelog): fix links 2022-06-29 15:27:32 +02:00
Cargo.lock fix(deps): update rust crate serde to 1.0.138 2022-07-02 11:35:45 +00:00
Cargo.toml fix(deps): update rust crate serde to 1.0.138 2022-07-02 11:35:45 +00:00
LICENSE initial commit 2022-06-11 12:42:32 +02:00
README.md chore(release): v0.4.0 2022-06-29 15:21:55 +02:00
renovate.json chore: setup renovatebot 2022-06-18 08:36:56 +02:00

README.md

crypto-utils

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.0"

How to use?

Compute a Sha hash

Add sha features (is enabled by default)

[dependencies]
crypto-utils = { version = "...", features = ["sha"] }

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

Add jwt features (is enabled by default)

[dependencies]
crypto-utils = { version = "...", features = ["jwt"] }

Create and decode a token

use crypto_utils::jsonwebtoken::{Claims, Token};

let secret = b"secret";
let user_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

// create claims
let claims = Claims::new(user_id, 24);

// create token
let token = Token::new(secret, claims).unwrap();

// decode token
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