Node JS MD5 + Base64
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

I need some code to be able to encrypt this string using MD5 and then convert it to base 64: <order></order>123456 in Node JS

The end result should be this: LghTkEmsD2tbQ3fsIBRcBg==

The PHP equivalent is this: base64_encode(hex2bin(md5('<order></order>123456')))

Just to let you know, md5 is a hashing algorithm, not encryption. So if you would like to decrypt it after that, I believe it's not possible.
Chlegou 4 months ago
I just need a way to transform this <order></order>123456 into this LghTkEmsD2tbQ3fsIBRcBg== in Node JS. The third party documentation only has a PHP method like this but no Node JS documentation base64_encode(hex2bin(md5('<order></order>123456')))
user0809 4 months ago
awarded to TheOsch

Crowdsource coding tasks.

2 Solutions

const md5 = require("md5")
const encodeHash = msg => Buffer.from(md5(msg)).toString("base64")

encodeHash takes a message, md5 encrypts it, stores it as bytes, and returns it in base 64 encoding.

I just tried this and it returns this MmUwODUzOTA0OWFjMGY2YjViNDM3N2VjMjAxNDVjMDY= instead of this LghTkEmsD2tbQ3fsIBRcBg==
user0809 4 months ago
Winning solution

const crypto = require("crypto");


It's the first variant. Here is the second one (a fix of B44ken's solution):

const md5 = require("md5");
const encodeHash = msg => Buffer.from(md5(msg), "hex").toString("base64");

Choose whatever you like.

View Timeline