使用场景:
在项目开发过程中涉及到安全测试,一般列表在系统中可以通过权限控制,但是很多通过id查看详情要求通过密文查询
官网:https://hashids.org/
GitHub:https://github.com/niieani/hashids.js
使用方法:
通过 npm install hashids 下载安装
引入hashids依赖, 封装加密方法
import Hashids from 'hashids'
/**
* @author: jinx
* @Date: 2021-09-22 17:57:49
* @param {String} salt 设置密文唯一值
* @param {*} length 密文长度
* @param {String} alphabet 密文组合字母表
* @return {String} encryptParam 返回密文
*/
export const hashids = (text) => {
let hashidstr = new Hashids('123456Tny8LIH9SQ22N172YndkQKiH1nO', 10, 'abcdefghijklmno12345pqrstuvwxyzABCDEFGHIJK67890LMNOPQRSTUVWXYZ')
let encryptParam = hashidstr.encode(text)
return encryptParam
}
业务中导入方法和使用加密方法
import { hashids } from '@/utils/hashids'
hashids(row.id) // 得到加密后的参数 例如 明文:9423,密文:'71PxEyb8zn'