当前位置:网站首页>TypeScript版加密工具PasswordEncoder
TypeScript版加密工具PasswordEncoder
2022-07-26 08:39:00 【码道功臣】
安装依赖
>npm i bcryptjs --save
添加代码PasswordEncoder.ts
const bcrypt = require('bcryptjs');
/** * 加密。加上前缀{bcrypt},为了兼容多种加密算法,这里暂时只实现bcrypt算法 */
export function encrypt(password) {
const salt = bcrypt.genSaltSync(5);
const hash = bcrypt.hashSync(password, salt, 64);
return '{bcrypt}' + hash;
}
/** * 解密 */
export function decrypt(password, hash) {
if (hash.indexOf('{bcrypt}') === 0) {
hash = hash.slice(8);
}
return bcrypt.compareSync(password, hash);
}
使用
const p = encrypt('123456');
const flag = decrypt('123456', p);
console.log(p);
console.log(flag);
边栏推荐
- The effective condition of MySQL joint index and the invalid condition of index
- JS工具函数大全
- 1、 Redis data structure
- Nodejs2day (modularization of nodejs, NPM download package, module loading mechanism)
- 利用模m的原根存在性判断以及求解
- Redis进阶
- Cadence(十)走线技巧与注意事项
- Mysql database connection / query index and other common syntax
- Flutter upgrade 2.10
- Kotlin operator
猜你喜欢
[C language] programmer's basic skill method - "creation and destruction of function stack frames"
Kotlin function
Spark persistence strategy_ Cache optimization
Human computer interaction software based on C language
[untitled]
[GUI] swing package (window, pop-up window, label, panel, button, list, text box)
OA项目之我的会议(会议排座&送审)
MySQL 8.0 OCP (1z0-908) has a Chinese exam
Mysql/mariadb (Galera multi master mode) cluster construction
Web3 Games: current situation and future
随机推荐
2022年全国职业院校技能大赛“网络安全”竞赛试题文件上传渗透测试答案Flag
Implementation of Prometheus web authentication and alarm
Flutter compilation fails
Oracle 19C OCP 1z0-082 certification examination question bank (19-23)
If Yi Lijing spits about programmers
Use index to optimize SQL query "suggestions collection"
基于C#实现的文件管理文件系统
[untitled]
2022-7-9 personal qualifying 6 competition experience
Huffman transformation software based on C language
Excel delete blank lines
Please tell me if there is any way to increase the write out rate when the Flink SQL client is in the sink table. When synchronizing through sink table
P1825 [USACO11OPEN]Corn Maze S
六、品达通用权限系统__pd-tools-log
Does flinkcdc now support sqlserver instance name connection?
A summary of practical websites that won't brighten people's eyes
Poor English, Oracle OCP or MySQL OCP exam can also get a high score of 80 points
Spark SQL common date functions
1、 Redis data structure
12306 ticket system crawling - 1. Saving and reading of city code data