当前位置:网站首页>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);
边栏推荐
- Web3 Games: current situation and future
- MySQL 8.0 OCP (1z0-908) has a Chinese exam
- The second lesson is the construction of development environment
- Status management bloc provider geTx
- Memory management - dynamic partition allocation simulation
- Cadence(十)走线技巧与注意事项
- The full name of flitter IDFA is identity for advertisers, that is, advertising identifiers. It is used to mark users. At present, it is most widely used for advertising, personalized recommendation,
- Fluent custom popupmenubutton
- Flitter imitates wechat long press pop-up copy recall paste collection and other custom customization
- Spark scheduling analysis
猜你喜欢
![[freeswitch development practice] user defined module creation and use](/img/5f/3034577e3e2bc018d0f272359af502.png)
[freeswitch development practice] user defined module creation and use

【加密周报】加密市场有所回温?寒冬仍未解冻 盘点上周加密市场发生的重大事件

Arbitrum launched the anytrust chain to meet the diverse needs of ecological projects

Seq2seq and attention model learning notes

2022-7-7 personal qualifying 4 competition experience

OA项目之我的会议(会议排座&送审)

Mysql8 one master one slave +mycat2 read write separation
![[untitled]](/img/3e/fb7c4d901643e6ea88a7d90ead045c.png)
[untitled]

Lesson 3: gcc compiler
![[untitled]](/img/89/c3ab79eb325f0136114a568745924b.png)
[untitled]
随机推荐
CV learning notes (optical flow)
Leetcode and query question summary
Oracle 19C OCP certification examination software list
C#入门系列(三十一) -- 运算符重载
Flutter text is left aligned with no blank space in the middle
Use index to optimize SQL query "suggestions collection"
基于C语言实现的人机交互软件
Inaccurate problem of flutter fijkplayer seekto
MySQL 8.0 OCP (1z0-908) has a Chinese exam
2022年收益率最高的理财产品是哪个?
2022-7-7 personal qualifying 4 competition experience
Oracle 19C OCP 1z0-082 certification examination question bank (13-18)
Redis advanced
Fluent uses protobuf
[GUI] GUI programming; AWT package (interface properties, layout management, event monitoring)
Kotlin variables and constants
What are the contents of Oracle OCP and MySQL OCP certification exams?
Xshell batch send command to multiple sessions
Winter vacation homework & Stamp cutting
23.2 customizing the banner control display hidden banner modify banner