Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NodeJS create md5 hash from string
var data = "do shash'owania";
var crypto = require('crypto');
crypto.createHash('md5').update(data).digest("hex");
@PhyrionX

This comment has been minimized.

Copy link

PhyrionX commented Nov 12, 2015

Thank you bro!!!

@roccomuso

This comment has been minimized.

Copy link

roccomuso commented Feb 6, 2016

Cool ;)

@mpaluru

This comment has been minimized.

Copy link

mpaluru commented Feb 14, 2016

Like!
Short, simple and useful.

@nick13jaremek

This comment has been minimized.

Copy link

nick13jaremek commented Feb 19, 2016

Thank you very much, pretty useful 😄

@vajahath

This comment has been minimized.

Copy link

vajahath commented Mar 2, 2016

yeah... useful... 👍
What are the possible parameters of digest() function besides hex ?

@indujuly

This comment has been minimized.

Copy link

indujuly commented Mar 14, 2016

Thanks. very useful to my project.
npm install crypto-js

@tomfuertes

This comment has been minimized.

@aborn

This comment has been minimized.

Copy link

aborn commented May 26, 2016

Cool, Very Useful!

@ghost

This comment has been minimized.

Copy link

ghost commented Jun 19, 2016

Thank you

@mattkosoy

This comment has been minimized.

Copy link

mattkosoy commented Jun 28, 2016

👍 gracias

@kevireilly

This comment has been minimized.

Copy link

kevireilly commented Aug 15, 2016

The one-liner of copy pasta:
require('crypto').createHash('md5').update('text to hash').digest('hex');

@gs-sgunasekaran

This comment has been minimized.

Copy link

gs-sgunasekaran commented Aug 19, 2016

Cool.. its very useful

@owntheweb

This comment has been minimized.

Copy link

owntheweb commented Aug 28, 2016

This saved me some time! Thanks. :D

@molinto

This comment has been minimized.

Copy link

molinto commented Nov 17, 2016

Thank you :)

@pittersnider

This comment has been minimized.

Copy link

pittersnider commented Dec 30, 2016

Cool, thank you so much!

@Server4001

This comment has been minimized.

Copy link

Server4001 commented Feb 6, 2017

Very helpful, thanks!

@VSG24

This comment has been minimized.

Copy link

VSG24 commented Apr 12, 2017

Cool.

@pragyandas

This comment has been minimized.

Copy link

pragyandas commented May 21, 2017

👍

@codingwesley

This comment has been minimized.

Copy link

codingwesley commented Jun 29, 2017

👍

@kryptstorm

This comment has been minimized.

Copy link

kryptstorm commented Jul 4, 2017

Cool! Thanks bro!

@Crusader4Christ

This comment has been minimized.

Copy link

Crusader4Christ commented Aug 15, 2017

For file it is better to use md5sum (for linux servers):

hash = exec("md5sum " + files.fd, {
   cwd: process.cwd(),
   encoding: 'utf8'
});
hash = hash.split(" ")[0];
@Booligoosh

This comment has been minimized.

Copy link

Booligoosh commented Sep 12, 2017

Thanks so much!!! Legend ;)

@zisad

This comment has been minimized.

Copy link

zisad commented Oct 27, 2017

MD5: 24af3b1d894893d66ea3372edaaa1cdc

@beany-vu

This comment has been minimized.

Copy link

beany-vu commented Nov 17, 2017

How can I generate a similar result from frontend side? I use cryptoJs
CryptoJS.MD5(hostname + version + TOKEN_KEY).toString()
The results are different from each other.
Thanks in advance,

@Nastya-Piu

This comment has been minimized.

Copy link

Nastya-Piu commented Jan 4, 2018

Thanks! 👍

@dixit7242

This comment has been minimized.

Copy link

dixit7242 commented Jan 12, 2018

Hi,
crypto.createHash('md5').update(data).digest("hex");
the above will return 32 digit hex(32byte hash), what if i want just 16 digit hex. could anybody help me here?

@realprogrammer5000

This comment has been minimized.

Copy link

realprogrammer5000 commented Feb 1, 2018

Thanks for not making me install another dependency! I wish people made more gists like this!

@chieunhatnang

This comment has been minimized.

Copy link

chieunhatnang commented Feb 3, 2018

It saves me from the error: 'Digest method not supported'. Thanks!

@arifliaqat

This comment has been minimized.

Copy link

arifliaqat commented Feb 14, 2018

Thanks its saving lot of my time

@IPcorps

This comment has been minimized.

Copy link

IPcorps commented Mar 20, 2018

Still thanks!

@DrobenyukA

This comment has been minimized.

Copy link

DrobenyukA commented Mar 23, 2018

Thank you!

@webber0928

This comment has been minimized.

Copy link

webber0928 commented Apr 9, 2018

Thank you !!

@sakuraline

This comment has been minimized.

Copy link

sakuraline commented Jun 29, 2018

buenas noches quisiera saber como encriptar con md5 en un chat web con node js

@aseevia

This comment has been minimized.

Copy link

aseevia commented Jul 6, 2018

Really helped, thanks!

@efkan

This comment has been minimized.

Copy link

efkan commented Aug 28, 2018

Thanks

@Stradivario

This comment has been minimized.

Copy link

Stradivario commented Sep 7, 2018

Thank you! Usable inside https://github.com/rxdi/main!

Searching for good implementation inside browser for the same purpose...

@indatawetrust

This comment has been minimized.

Copy link

indatawetrust commented Sep 10, 2018

const md5 = data => crypto.createHash('md5').update(data).digest("hex")
@pranatayudha

This comment has been minimized.

Copy link

pranatayudha commented Nov 22, 2018

const md5 = data => crypto.createHash('md5').update(data).digest("hex")

can decrypt that data after using this method?

@kidkkr

This comment has been minimized.

Copy link

kidkkr commented Nov 27, 2018

const md5 = data => crypto.createHash('md5').update(data).digest("hex")

can decrypt that data after using this method?

@pranatayudha No you can't. md5 is a hash function

@CQBinh

This comment has been minimized.

Copy link

CQBinh commented Jan 10, 2019

Thank bro!

@karacas

This comment has been minimized.

Copy link

karacas commented Jan 13, 2019

nice!

@albertmourato

This comment has been minimized.

Copy link

albertmourato commented Feb 27, 2019

Hey @beany-vu, were you able to use crypto from the frontend side properly? I'm trying to do the same but it's not working well...

@alfonmga

This comment has been minimized.

Copy link

alfonmga commented Mar 21, 2019

@albertmourato crypto is a NodeJS module, so you can't use it in the frontend side.

@KDWangBoss

This comment has been minimized.

Copy link

KDWangBoss commented Apr 19, 2019

thanks

@denys-ua

This comment has been minimized.

Copy link

denys-ua commented May 11, 2019

Thanks, dude!

@abhijiy

This comment has been minimized.

Copy link

abhijiy commented May 29, 2019

Is it possible to decrypt the string? Can someone give me sample code for that? I have used for encryption
crypto.createHash('md5').update(req.body.userType.trim() + constants.APIKEY).digest("hex")

@diachedelic

This comment has been minimized.

@ankur20us

This comment has been minimized.

Copy link

ankur20us commented Jun 10, 2019

Is it possible to decrypt the string? Can someone give me sample code for that? I have used for encryption
crypto.createHash('md5').update(req.body.userType.trim() + constants.APIKEY).digest("hex")
Hashing is not encryption. You can't come to original state once you get the hashed version.

@smitthakkar1

This comment has been minimized.

Copy link

smitthakkar1 commented Aug 8, 2019

Thnanks bro

@SyedFaraz55

This comment has been minimized.

Copy link

SyedFaraz55 commented Oct 11, 2019

Thank you so much @gistfile1.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.