当前位置:网站首页>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);
边栏推荐
- 各位老师,请问在flinkcdc中,sqlserver如何获取到ddl?
- 请问现在flinkcdc支持sqlserver实例名方式连接吗?
- Oracle 19C OCP 1z0-082 certification examination question bank 1
- Poor English, Oracle OCP or MySQL OCP exam can also get a high score of 80 points
- 1、 Redis data structure
- import error: ‘Icon‘ is not exported from ‘antd‘. Import icon error
- Inaccurate problem of flutter fijkplayer seekto
- Code cloud change remote warehouse command
- Mysql database connection / query index and other common syntax
- Seq2seq and attention model learning notes
猜你喜欢
随机推荐
请问现在flinkcdc支持sqlserver实例名方式连接吗?
基于C语言实现的人机交互软件
Write common API tools swagger and redoc
23.10 Admin features
JS tool function Encyclopedia
基于Raft共识协议的KV数据库
Web3 Games: current situation and future
[freeswitch development practice] user defined module creation and use
Automation and disconnection monitoring of video addition
Oracle 19C OCP 1z0-083 question bank (7-12)
2022-7-5 personal qualifying 2 competition experience
2022-7-8 personal qualifying 5 competition experience (supplementary)
Analysis on the query method and efficiency of Oracle about date type
Use of room database in kotlin
Oracle 19C OCP 1z0-082 certification examination question bank (7-12)
Redis进阶
基于C语言设计的换乘指南打印系统
C#入门系列(三十一) -- 运算符重载
Mysql/mariadb (Galera multi master mode) cluster construction
Human computer interaction software based on C language









