I encode a string 'test me ąčęėįš' in javascript like this:
function toBinary(string) {
const codeUnits = new Uint16Array(string.length);
for (let i = 0; i < codeUnits.length; i++) {
codeUnits[i] = string.charCodeAt(i);
}
return String.fromCharCode(...new Uint8Array(codeUnits.buffer));
}
console.log(btoa(toBinary('test me ąčęėįš')));
// output: dABlAHMAdAAgAG0AZQAgAAUBDQEZARcBLwFhAQ==
If I encode the same string i Oracle base64 encoding generates different output:
select utl_encode.BASE64_ENCODE(utl_raw.cast_to_raw('test me ąčęėįš')) from dual;
-- output 6447567A644342745A534467364F62723466413D
Why is that? Does BASE64 encoding/decoding work differently in Oracle and javascript? Of course when I try in Oracle decode javascript encoded string it not work:
select utl_encode.base64_decode('dABlAHMAdAAgAG0AZQAgAAUBDQEZARcBLwFhAQ==') from dual;
-- output: ORA-01465: invalid hex number
How in Oracle decode in javascript base64 encoded string?