🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[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"); } } ```