3 stable releases
Uses new Rust 2024
| 1.0.7 | May 24, 2025 |
|---|
#1747 in Cryptography
25KB
375 lines
JSON Web Token generation and verification lightweight library, hash algorithm currently only supports hs256
author: kiven lee date: 2023-07-01
jwt -- simple JSON web token library
简单的jwt实现库
项目地址
https://gitee.com/kivensoft/jwt_rs
第三方依赖
- log
- anyhow
- serde
- serde_json
- base64
- sha2
- hmac
- rsa [optional]
添加依赖
cargo add --git https://gitee.com/kivensoft/jwt_rs jwt
使用
use jwt;
use serde_json;
fn main() {
let s = jwt::encode(&serde_json::json!({
"userId": 1,
"username": "admin",
}), "password", "my_issuer", 86400).unwrap();
let s2 = jwt::decode(&s, "password", "accinfo").unwrap();
assert_eq!("admin", s2["username"].as_str());
}
Dependencies
~1.4–3MB
~66K SLoC