# jf-jwt

> **安装** ``` npm i jf-jwt --save ```

Latest version **1.0.0** (published 2021-03-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install jf-jwt
pnpm add jf-jwt
yarn add jf-jwt
bun add jf-jwt
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-03-02 |
| First published | 2021-03-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 42.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | wolfe |
| Maintainers | wolfe |

## Links

- npm: https://www.npmjs.com/package/jf-jwt
- npm.io page: https://npm.io/package/jf-jwt

## Recent versions

- 1.0.0 (latest) — 2021-03-02

## README

## jf-jwt

**安装**
```
npm i jf-jwt --save
```

```javascript
const jwt = require('jf-jwt')

/**
 * jwt签名
 * @param {*} jsonObject 要加密的json对象
 * @params secret 密钥
 * @params expiresIn 
 */
export function jwtEncode(jsonObject, secret, expiresIn = '120s') {
  const loginRes = getLoginRes()
  const token = jwt.sign({}, secret, {
    algorithm: 'HS256',
    subject: JSON.stringify(jsonObject || '{}'),
    expiresIn
  })
  return token
}

/**
 * jwt解签
 * @params signString jwt加密的字符串
 * @params secret 密钥
 * @params expiresIn 7199秒，将近2小时，也就是从接口返回加密串，2小时后再解就解不了
 */
export function jwtDecode(signString, secret = '', expiresIn = 7199) {
  const decoded = jwt.verify(signString, secret, {
    algorithms: ['HS256'],
    maxAge: expiresIn
  })
  return decoded
}

```

---
_Source: https://npm.io/package/jf-jwt · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
