解密密码由crypto.pbkdf2对象创建 [英] Decrypt Password Created by crypto.pbkdf2 Object
问题描述
encryptPassword:function(password){
if(!password ||!this.salt)return'';
var salt = new Buffer(this.salt,'base64');
return crypto.pbkdf2Sync(password,salt,10000,64).toString('base64');
}
如何实现解密功能?
它可以在java或javascript中。
Thx!
PBKDF2是一种单向散列算法。不可能解密生成的散列。您可以阅读有关此此处的更多信息。
单向哈希执行一系列数学运算,
将输入转换为(主要)唯一的输出,称为摘要。
因为这些操作是一种方法,所以你无法'解密'输出
你不能将摘要转换成原始输入。
如果要使用PBKDF2存储和比较密码,您可能对 pbkdf2
库。它使密码的生成和比较变得简单:
var pbkdf2 = require('pbkdf2');
var p ='password';
var s = pbkdf2.generateSaltSync(32);
var pwd = pbkdf2.hashSync(p,s,1,20,'sha256');
var bool = pbkdf2.compareSync(pwd,p,s,1,20,'sha256');
I have the following code in javascript, running on NodeJs:
encryptPassword: function(password) {
if (!password || !this.salt) return '';
var salt = new Buffer(this.salt, 'base64');
return crypto.pbkdf2Sync(password, salt, 10000, 64).toString('base64');
}
How can I implement the decrypt function? It can be in java or in javascript.
Thx!
PBKDF2 is a one-way hashing algorithm. It's not possible to decrypt the generated hash. You can read more about this here.
A one way hash performs a bunch of mathematical operations that transform input into a (mostly) unique output, called a digest. Because these operations are one way, you cannot ‘decrypt’ the output- you can’t turn a digest into the original input.
If you want to use PBKDF2 to store and compare passwords, you might be interested in the pbkdf2
library. It makes generation and comparison of passwords easy:
var pbkdf2 = require('pbkdf2');
var p = 'password';
var s = pbkdf2.generateSaltSync(32);
var pwd = pbkdf2.hashSync(p, s, 1, 20, 'sha256');
var bool = pbkdf2.compareSync(pwd, p, s, 1, 20, 'sha256');
这篇关于解密密码由crypto.pbkdf2对象创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!