I try to convert GUID in base64 string for some reasons in Node.js
My function is
function encode(guid) {
let buffer = new Buffer(guid.replace(/-/g, ""), 'hex');
let ret = buffer.toString('base64');
ret = ret.replace(/\//g, "_").replace(/\+/g, "-");
return ret.substring(0,22); //FIXME
}
function decode(encoded_string) {
let buffer = new Buffer(encoded_string + '==', 'base64');
let ret = buffer.toString('hex');
ret = ret.replace(/_/g, "/").replace(/-/g, "+");
return ret;
}
I tested with guid = 'c9a646d3-9c61-4cb7-bfcd-ee2522c8f633'
and the result was 'yaZG05xhTLe_ze4lIsj2Mw'
and also it has decoded well (without dash).
However, according to the http://guid-convert.appspot.com/
The converted result was '00amyWGct0y/ze4lIsj2Mw=='.
I believe I might did something wrong, but can't find what I did wrong.