Reputation: 487
From this stackoverflow question: Convert 'String' to Base64 encode of MD5 'String' in c# .net how can I port this code/algorithm to frontend javascript?
From: password
To: X03MO1qnZdYdgyfeuILPmQ==
I've tried btoa
etc. but yielded different results
Upvotes: 0
Views: 1393
Reputation: 487
Suggested by Leyon of using Crypto-JS library, I've added a code to convert it to Base64 from Hex output of Crypto-JS. I think this is not the best answer but this helps me, for now.
var md5 = function(value) {
return CryptoJS.MD5(value).toString();
}
function hexToBase64(str) {
return btoa(String.fromCharCode.apply(null,
str.replace(/\r|\n/g, "").replace(/([\da-fA-F]{2}) ?/g, "0x$1 ").replace(/ +$/, "").split(" "))
);
}
$("input").keyup(function () {
var value = $(this).val(),
hash = md5(value);
$(".test").html(hash);
$(".base64").html(hexToBase64(hash));
});
Upvotes: 2