This is an active fork of https://github.com/GildedHonour/frank_jwt
Implementation of JSON Web Tokens in Rust.
- HS256
- HS384
- HS512
- RS256
- RS384
- RS512
- ES256
- ES384
- ES512
- Sign
- Verify
- iss (issuer) check
- sub (subject) check
- aud (audience) check
- exp (expiration time) check
- nbf (not before time) check
- iat (issued at) check
- jti (JWT id) check
Put this into your Cargo.toml
:
[dependencies]
rusty_jwt = "<current version of frank_jwt>"
And this in your crate root:
extern crate rusty_jwt;
use rusty_jwt::{Header, Payload, Algorithm, encode, decode};
//HS256
let mut payload = Payload::new();
payload.insert("key1".to_string(), "val1".to_string());
payload.insert("key2".to_string(), "val2".to_string());
let header = Header::new(Algorithm::HS256);
let secret = "secret123";
let jwt = encode(header, secret.to_string(), payload.clone());
//public key signatures:
use std::fs::File;
use std::io::Read;
let mut payload = Payload::new();
payload.insert("key1".to_string(), "val1".to_string());
payload.insert("key2".to_string(), "val2".to_string());
let header = Header::new(Algorithm::RS256);
let public_key_path = //... path to your public key, needs to be pem formated.
let mut key_file = File::open(private_key_path).expect("Unable to open private key file");
let mut key_pem: Vec<u8> = Vec::new();
file.read_to_end(&mut key_pem).expect("Unable to read pem from file");
let jwt = encode(header, key_pem, payload);
Apache 2.0
cargo test