ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ### 封装Crypto作为egg.js 专用加密函数 1. 安装 `npm install crypto --save` 2. 配置文件配置 config / config.default.js ``` config.crypto = { secret: 'ghdgw@45njashdaksh2!#@3nxjdas_*672' }; ``` 3. 扩展application对象 app / extend / application.js ``` const jwt = require('jsonwebtoken'); const crypto = require('crypto'); module.exports = { get jwt() { return jwt; }, cryptoHmac(param) { const hmac = crypto.createHash("sha256",this.config.crypto.secret); hmac.update(param); return hmac.digest("hex"); } } ```