Decrypt Password Created by crypto.pbkdf2 Object

北城以北 提交于 2020-01-14 14:11:44

问题


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!


回答1:


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');


来源:https://stackoverflow.com/questions/24563847/decrypt-password-created-by-crypto-pbkdf2-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!