Java
using import com.sun.org.apache.xml.internal.security.utils.Base64;
byte[] b = new byte[] { 12, 3, 4, 5, 12 , 34, 100 }; String encoded = Base64.encode(b);
gives:
"DAMEBQwiZA=="
Javascript
use atob and btoa
var stringToByteArray = function(str) { var bytes = []; for (var i = 0; i < str.length; ++i) { bytes.push(str.charCodeAt(i)); } return bytes; }; var decoded = stringToByteArray(atob("DAMEBQwiZA=="));
gives:
[ 12, 3, 4, 5, 12 , 34, 100 ]
Note. If you do this in NodeJS, look at the atob package.
source share