![github] ![crates-io] ![docs-rs] ![CI]
Cryptography Utils for Rust
The driver is available on [crates-io]. To use the driver in
your application, simply add it to your project's Cargo.toml
.
toml
[dependencies]
crypto-utils = "0.2.0"
Add sha
features (is enabled by default)
toml
[dependencies]
crypto-utils = { version = "...", features = ["sha"] }
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 hashbytes = CryptographicHash::hash(Algorithm::SHA1, input.asbytes()); // Vec
// decode hash to a String let hash = hex::encode(hash_bytes); // String
asserteq!(hash, "21bd12dc183f740ee76f27b78eb39c8ad972a757".tostring()) ```
Add jwt
features (is enabled by default)
toml
[dependencies]
crypto-utils = { version = "...", features = ["jwt"] }
Create and decode a token
```rust 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(); ```
License: MIT