Reputation: 523
I have a string that I would like to hash, to have it look something like 51e7fae2d7b2b5388de06bc205e4a3ca. Then I'd like to be able to dehash it (without salting). I know this is not secure at all, but this isn't for security. I've tried using crypto from NodeJS, but there seems to be no way to retrieve an MD5 hash (without using some large database)
Upvotes: 1
Views: 1377
Reputation: 1197
Hashing is one way and irreversible. What you want is encoding and decoding. Base64 is often used for what you're wanting:
// encode
new Buffer("Hello World").toString('base64');
//=> SGVsbG8gV29ybGQ=
// decode
new Buffer("SGVsbG8gV29ybGQ=", 'base64').toString('ascii');
//=> Hello World
Upvotes: 2
Reputation: 12662
Hashes cannot be de-hashed. What you're trying to do is completely impossible. The closest that things come is looking up the hash in a database, but truly de-hashing MD5 is impossible.
Here's how hashes are meant to be used (for login on a site): When the user creates an account, the password is hashed, and the hash is stored in a database. Then, whenever they try to login, the password they enter is hashed, and if the hash matches the one in the database, then they must have the correct password.
The advantage of this is that if a hacker manages to get access to the database, they still can't get access to the user's password; all they have is the hash. And since the hashes cannot be converted back into the original password, the hacker has effectively managed to get access to some random alphanumeric characters.
If you want to be able to "de-hash" things, then you should be using encryption instead. CryptoJS supports AES encryption, which is probably the most popular algorithm.
Upvotes: 1