Converting a hexadecimal string to base64 in javascript -


this question has answer here:

now have string of md5 hex digest file, , want convert base64 in order use content-md5 http header when uploading it.

any appreciated

var hexarray = myhexstring     .replace(/\r|\n/g, "")     .replace(/([\da-fa-f]{2}) ?/g, "0x$1 ")     .replace(/ +$/, "")     .split(" "); var bytestring = string.fromcharcode.apply(null, hexarray); var base64string = window.btoa(bytestring); 

see here btoa docs: https://developer.mozilla.org/en-us/docs/web/api/windowbase64/btoa

also polyfill: https://stackoverflow.com/a/23190164/275501


Comments