Decrypt Password Created by crypto.pbkdf2 Object
我在javascript上运行以下代码,在NodeJ上运行:
1 2 3 4 5 | 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。
谢谢!
PBKDF2是一种单向哈希算法。 无法解密生成的哈希。 您可以在此处了解更多信息。
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.
如果要使用PBKDF2来存储和比较密码,您可能会对
1 2 3 4 5 | 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'); |