How can I generate an MD5 hash of a String, from JavaScript running on PhantomJS ?
I tried npm install -g crypto
but the crypto module is not found.
PhantomJs does not natively support MD5 but you can easily inject external script code using phantom.injectJs.
You have just a find an implementation in javascript. MD5 is quite popular and not too difficult to implent. So there are many implementations such as crypto-js or wbond/md5-js.
A very basic script using CryptoJS could be
var system = require('system');
if (system.args.length != 2) {
console.log("Usage: phantomjs md5_test.js input");
} else {
if(phantom.injectJs('md5.js')) {
console.log(CryptoJS.MD5(system.args[1]));
phantom.exit();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With