kjwt 1.0.7

mini JSON Web Token library
Documentation

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());
}