-2

Tried to see my password from my database.My password is test123 So in my database i have saved like this : $2a$10$0V1JkVfl8n.WD/QbInIWqubjcaxnCCnP3K.bhuxjAQbJ9LyFiNTdu. How to see my password again like test123 from $2a$10$0V1JkVfl8n.WD/QbInIWqubjcaxnCCnP3K.bhuxjAQbJ9LyFiNTdu.

Can we do using nodejs or javascript?

    var crypto = require("crypto");
    var password = '$2a$10$0V1JkVfl8n.WD/QbInIWqubjcaxnCCnP3K.bhuxjAQbJ9LyFiNTdu';  
    var algorithm = "aes-192-cbc"; //algorithm to use
     
    const key = crypto.scryptSync(password, 'salt', 24); //create key
    var text = '?????????????????????????"; //text to be encrypted

    const iv = Buffer.alloc(16, 0);
    const cipher = crypto.createCipheriv(algorithm, key, iv);
    var encrypted = cipher.update(text, 'utf8', 'hex') + cipher.final('hex'); // encrypted text

    const decipher = crypto.createDecipheriv(algorithm, key, iv);
    var decrypted = decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8');  

    console.log(decrypted);  //Output should be like test123
Pappa S
  • 303
  • 1
  • 8
  • 21

3 Answers3

1

I don't believe it's meant to be decrypted on purpose.

"Cryptographic hash functions are a special type of one-way calculation"

What is hashing?

Cryptographic hash functions are a special type of one-way calculation. They take a string of data of any size and always give an output of a predetermined length. This output is called the hash, hash value or message digest. Since these functions don’t use keys, the result for a given input is always the same.


Encryption, hashing, salting – what’s the difference?

StackOverflow question:

"HMAC is a MAC/keyed hash, not a cipher. It's not designed to be decrypted. If you want to encrypt something, use a cipher, like AES, preferably in an authenticated mode like AES-GCM.

The only way to "decrypt" is guessing the whole input and then comparing the output."

How can I decrypt a HMAC?

codingwithmanny
  • 1,126
  • 8
  • 20
0

All these encrypting algorithms are trying NOT to do exactly what you are asking for :). It's a one way process. That means there is no well-known library in javascript or nodejs world to easily decrypt your password. Maybe there might be some applications, just using try-and-error method to guess your password.

Halil Azyikmis
  • 139
  • 1
  • 5
0

It's not possible. Your password had the following functions applied.

  • Saved value = HASH(Password + salt)

That can't be undone.

Warren Parad
  • 3,910
  • 1
  • 20
  • 29