当前位置:网站首页>Typescript encryption tool passwordencoder
Typescript encryption tool passwordencoder
2022-07-26 08:47:00 【Code road hero】
Installation dependency
>npm i bcryptjs --save
Add code PasswordEncoder.ts
const bcrypt = require('bcryptjs');
/** * encryption . Add the prefix {bcrypt}, In order to be compatible with various encryption algorithms , For the time being, only bcrypt Algorithm */
export function encrypt(password) {
const salt = bcrypt.genSaltSync(5);
const hash = bcrypt.hashSync(password, salt, 64);
return '{bcrypt}' + hash;
}
/** * Decrypt */
export function decrypt(password, hash) {
if (hash.indexOf('{bcrypt}') === 0) {
hash = hash.slice(8);
}
return bcrypt.compareSync(password, hash);
}
Use
const p = encrypt('123456');
const flag = decrypt('123456', p);
console.log(p);
console.log(flag);
边栏推荐
- Cve-2021-26295 Apache OFBiz deserialization Remote Code Execution Vulnerability recurrence
- P1825 [USACO11OPEN]Corn Maze S
- My meeting of OA project (meeting seating & submission for approval)
- Espressif 玩转 编译环境
- 基于C语言设计的换乘指南打印系统
- [recommended collection] MySQL 30000 word essence summary index (II) [easy to understand]
- Study notes of automatic control principle --- stability analysis of control system
- Flutter custom player progress bar
- 23.5 event listeners of application events and listeners
- 23.8 using the applicationrunner or commandlinerunner to implement applicationrunner and commandlinerunner
猜你喜欢

Cadence(十)走线技巧与注意事项

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

Kotlin属性与字段

Foundry教程:使用多种方式编写可升级的智能合约(上)

基于Raft共识协议的KV数据库

Excel delete blank lines

Arbitrum Nova release! Create a low-cost and high-speed dedicated chain in the game social field

MySQL 8.0 OCP (1z0-908) has a Chinese exam

为什么要在时钟输出上预留电容的工位?

【加密周报】加密市场有所回温?寒冬仍未解冻 盘点上周加密市场发生的重大事件
随机推荐
Oracle 19C OCP 1z0-082 certification examination question bank (51-60)
Maximum common substring & regularity problem
Mycat2 sub database and sub table
基于C语言的内存管理-动态分区分配方式模拟
2022年收益率最高的理财产品是哪个?
[recommended collection] MySQL 30000 word essence summary + 100 interview questions (I)
Oracle 19C OCP 1z0-082 certification examination question bank (42-50)
Pan micro e-cology8 foreground SQL injection POC
有限元学习知识点备案
Registration of finite element learning knowledge points
[encryption weekly] has the encryption market recovered? The cold winter still hasn't thawed out. Take stock of the major events that occurred in the encryption market last week
1、 Redis data structure
23.5 event listeners of application events and listeners
Okaleido上线聚变Mining模式,OKA通证当下产出的唯一方式
In the first year of L2, the upgrade of arbitrum nitro brought a more compatible and efficient development experience
解决C#跨线程调用窗体控件的问题
Oracle 19C OCP 1z0-082 certification examination question bank (7-12)
[freeswitch development practice] use SIP client Yate to connect freeswitch for VoIP calls
OA项目之我的会议(会议排座&送审)
Implementation of Prometheus web authentication and alarm