b64DecodeUnicode(str) {
// Going backwards: from bytestream, to percent-encoding, to original string.
return decodeURIComponent(atob(str).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
I tried using atob, then I tried using the above. It's a pem file, doing:
openssl x509 -in valid.pem -text -noout
and it gives valid output.
The text content looks like: data:application/x-x509-ca-cert;base64,QpDQXdHVVhWbFltVmp... instead of this: -----BEGIN CERTIFICATE-----... and it cannot be converted from base64.
I kept getting:
String contains an invalid character. The "data:application/x-x509-ca-cert;base64," part, is there a way to remove it from the reader.result?
const reader = new FileReader()
reader.onload = (e) => {
reader.result
...
}
I am guessing every pem file starts with "data:application/x-x509-ca-cert;base64,", but is there a way to remove it without hardcoding the string and removing that substring from the content?
I would like to avoid using:
replace('data:application/x-x509-ca-cert;base64,', '')