# ohos_jsonwebtoken **Repository Path**: openharmony-sig/ohos_jsonwebtoken ## Basic Information - **Project Name**: ohos_jsonwebtoken - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: https://gitee.com/openharmony-sig/ohos_jsonwebtoken - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 10 - **Created**: 2023-08-24 - **Last Updated**: 2025-05-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 🚨 **重要提示 | IMPORTANT** > > **⚠️ 此代码仓已归档。新地址请访问 [ohos_jsonwebtoken](https://gitcode.com/openharmony-sig/ohos_jsonwebtoken)。| ⚠️ This repository has been archived. For the new address, please visit [ohos_jsonwebtoken](https://gitcode.com/openharmony-sig/ohos_jsonwebtoken).** > --- > # @ohos/jsonwebtoken ## 介绍 JSON Web Token(JWT)是一个开放的行业标准(RFC 7519),它定义了一种简洁的、自包含的协议格式,用于在通信双方传递json对象,传递的信息经过数字签名可以被验证和信任。[@ohos/jsonwebtoken](https://github.com/auth0/node-jsonwebtoken)是一款适用于 openharmony 环境的 Json Web Token实现。本库基于 [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken)原库 v9.0.1 版本进行适配。 ## 下载安装 ``` ohpm install @ohos/jsonwebtoken ``` > OpenHarmony ohpm 环境配置等更多内容,请参考[如何安装 OpenHarmony ohpm 包](https://gitee.com/openharmony-tpc/docs/blob/master/OpenHarmony_har_usage.md) ## 使用说明 ### 基本使用示例 1. 同步签名 ( 默认算法:HMAC SHA256 ) ```js import jwt from "@ohos/jsonwebtoken"; var token = jwt.sign({ foo: 'bar' }, 'shhhhh'); ``` 2. 异步签名 ```js jwt.sign({ foo: 'bar' }, privateKey, { algorithm: 'RS256' }, function(err, token) { console.log(token); }); ``` 2. RSA SHA256算法,使用私钥同步签名 ```js // sign with RSA SHA256 var privateKey = ""; var token = jwt.sign({ foo: 'bar' }, privateKey, { algorithm: 'RS256' }); ``` 4. RSA SHA256算法,使用公钥验证签名 ```js var publicKey = "" const decoded = jwt.verify(signatrue,publicKey); ``` ## 接口 | 模块名 | 功能 | 备注 | |------------------------------|-----|---| | sign(payload,secret,options) | 签名 | | | verify(signature,publicKey) | 验签 | | 更多模块的使用可参考[官方文档](https://github.com/auth0/node-jsonwebtoken/blob/master/README.md),单元测试用例详情见[TEST.md](https://gitee.com/openharmony-sig/ohos_jsonwebtoken/blob/master/TEST.md) ## 约束与限制 在下述版本验证通过: - DevEco Studio: NEXT Beta1-5.0.3.806, SDK: API12 Release(5.0.0.66) - DevEco Studio: 4.0 Canary2(4.0.1.400), SDK: API10 (4.0.0.24) Beta1 ## 贡献代码 使用过程中发现任何问题都可以提 [Issue](https://gitee.com/openharmony-sig/ohos_jsonwebtoken/issues)给组件,当然,也非常欢迎发 [PR](https://gitee.com/openharmony-sig/ohos_jsonwebtoken/pulls)共建 。 ## 开源协议 本项目基于 [Apache License 2.0](https://gitee.com/openharmony-sig/ohos_jsonwebtoken/blob/master/LICENSE) ,请自由地享受和参与开源。