Search code examples
node.jscryptojs

How to decrypt hash get from this function


we are encrypting our password in the app using this function.How to decrypt them when we need actual string.var crypto = require('crypto');

function encryptPassword(password) {
    var salt = new Buffer('priotzen', 'base64');
    return crypto.pbkdf2Sync(password, salt, 10000, 64).toString('base64');
}

Thanks :)


Solution

  • The code you've provided generates a one-way hash. If you use this, then you validate passwords by comparing hashed values. There is no way to decrypt the existing password. If the user forgets their password, then you do a password reset.

    If you really want to have retrievable passwords, then you need to look at encryption rather than hashing algorithms. For this type of application, symmetric key encryption, such as AES may be suitable.

    Keep in mind that encryption is computationally much more expensive than hashing, and less secure. Hashing is nearly always preferred for passwords. Unless there is some extremely compelling reason to have retrievable passwords, you should steer your client towards one-way hash passwords.