I'm currently trying to decode my base64 encoded string. The issue I'm facing is it gives me junk decoded result but when I remove 77u_ in front from it, the decode result will get fine. My question is that, is there any other way to decode it?
Following is my encoded string:
77u_RGF0ZSxUeXBlLENvbmZpcm1hdGlvbiBDb2RlLFN0YXJ0IERhdGUsTmlnaHRzLEd1ZXN0LExpc3RpbmcsRGV0YWlscyxSZWZlcmVuY2UsQ3VycmVuY3ksQW1vdW50LFBhaWQgT3V0LEhvc3QgRmVlLENsZWFuaW5nIEZlZSxHcm9zcyBFYXJuaW5ncyxPY2N1cGFuY3kgVGF4ZXMNCjEwLzMwLzIwMTgsUmVzZXJ2YXRpb24sSE05U1BUOUNYQywxMC8yOS8yMDE4LDMsQWFyb24gSmFibG9uc2tpLEVsZWdhbnQgUHJpdmF0ZSBSb29tIGluIGEgTW9kZXJuIEx1eHVyeSBCdW5nYWxvdywsLFVTRCwxNDUuNTAsLDQuNTAsMzAuMDAsMTUwLjAwLDIxLjANCjEwLzI2LzIwMTgsUmVzZXJ2YXRpb24sSE0zM0gyWEU0SiwxMC8yNS8yMDE4LDMsWWIgQmFiaWUsRWxlZ2FudCBQcml2YXRlIFJvb20gaW4gYSBNb2Rlcm4gTHV4dXJ5IEJ1bmdhbG93LCwsVVNELDE3NC42MCwsNS40MCwzMC4wMCwxODAuMDAsMjUuMg0KMTAvMjIvMjAxOCxSZXNlcnZhdGlvbixITVdSRk1KNU1LLDEwLzIxLzIwMTgsNCxHYWJyaWVsbGEgRGFsdG9uLEVsZWdhbnQgUHJpdmF0ZSBSb29tIGluIGEgTW9kZXJuIEx1eHVyeSBCdW5nYWxvdywsLFVTRCwxNjQuOTAsLDUuMTAsMzAuMDAsMTcwLjAwLDIzLjgNCjEwLzE4LzIwMTgsUmVzZXJ2YXRpb24sSE1NUFk4UDJRRiwxMC8xNy8yMDE4LDQsUMOpdGVyIFZhcmdhLEVsZWdhbnQgUHJpdmF0ZSBSb29tIGluIGEgTW9kZXJuIEx1eHVyeSBCdW5nYWxvdywsLFVT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GTk04RFcsMTAvMDMvMjAxOCw2LFNhbmRybyBDemVrYWksRWxlZ2FudCBQcml2YXRlIFJvb20gaW4gYSBNb2Rlcm4gTHV4dXJ5IEJ1bmdhbG93LCwsVVNELDM3OC4zMCwsMTEuNzAsMzAuMDAsMzkwLjAwLDU0LjYNCjEwLzAxLzIwMTgsUmVzZXJ2YXRpb24sSE1UUzk0Uk1FMywwOS8zMC8yMDE4LDMsQnJhbmRlbiBIaWNrcyxFbGVnYW50IFByaXZhdGUgUm9vbSBpbiBhIE1vZGVybiBMdXh1cnkgQnVuZ2Fsb3csLCxVU0QsMTE2LjQwLCwzLjYwLDMwLjAwLDEyMC4wMCwxNi44DQo
It's the _ that messes up the result. Everything else is perfectly fine base64 encoded. The base64 code table doesn't contain a _, it is a substitiution character for / in base64url encoding.
When you replace _ with / the decoding works fine.
When I tested it on https://www.base64decode.org/ and chose ASCII as the source character set, I got  in front of the text, which is the byte order mark for UTF-8. When I changed to utf-8, there was nothing visible in front of the text.
A short test in node.js also proves that '77u/' is indeed the base64 code of the BOM:
var messageB64 ='77u/'
var buf = Buffer.from(messageB64, 'base64');
console.log(buf) // output: <Buffer ef bb bf>
Conclusion:
your data is base64url decoded
you should change it back to base64 code before you decode
the extra characters are a harmless byte order marker which is invisible if you use utf-8 encoding.
Related
I have base64 encoded text and I try to decode it but when I decode it, it contains some unknown characters. But the interesting part is, decoded text contains that I need data. So just I need to remove unknown characters and I need to split the data.
Do you have any suggestion to escape this unknown characters?
E.g base64 data:
Ct5bChoKCgjOzdDH7KDX+X4SCgjb1uri1IOfgUUaABABMgVlbi1VUzrYJAoFZW4tVVMaCVdpbiBDb2xvciK7C1dpbiBDb2xvciBvciBDb2xvciBXaW4gaXMgbm90IGp1c3QgYSBnYW1lLiBJdCBpcyBhIGlkZW9sb2d5IGluIHRoZSBzYW1lIHRpbWUuCldhdGNoIG91dDogU29tZSBjb2xvcnMgd2lsbCBhcHBlYXIgb24gdGhlIHNjcmVlbi4gVHJ5IHRv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WMKIC0gSmFwYW5lc2UKIC0gR2VybWFuCiAtIEZyZW5jaAogCkdhbWVwbGF5OgotIFdhdGNoIG91dCBmb3IgdGhlIGNvbG9ycyBpbiB0aGUgbWlkZGxlLgotIEFmdGVyIGEgd2hpbGUsIG5vdGljZSB0aGUgZGlzYXBwZWFyYW5jZXMgb2YgdGhlc2UgY29sb3JzIGFuZCBpZGVudGlmeSB0aGVtLgotIFNlbGVjdCB0aGUgY29sb3JzIHlvdSBzcGVjaWZ5IGZyb20gdGhlIGNvbG9yIHBhbmVsLgoKRm9sbG93IFVzOgotIGh0dHBzOi8vd3d3LmZhY2Vib29rLmNvbS9zaGFnYW1lcwotIGh0dHBzOi8vdHdpdHRlci5jb20vc2hhX2dhbWVzCi0gaHR0cHM6Ly9wbHVzLmdvb2dsZS5jb20vdS8wLzExMTMwOTUyMjcxNTM1MjE2ODY4OSpJQ29sb3IsIHdpbiwgZ2FtZSwgcmFjZSwgYmVzdCwgZGlmZmVyZW50LCBpbXByb3ZlLCBza2lsbCwgZWFzeSwgYnJhaW4sIGJ1eTIAEhcKE0V4dGVybmFsIEV4cGVyaW1lbnQQAg==
It is a base64 encoded protobuf data. you can decode it from https://protogen.marcgravell.com
I created a .docx file.
Now, I do this:
// read the file to a buffer
const data = await fs.promises.readFile('<pathToMy.docx>')
// Converts the buffer to a string using 'utf8' but we could use any encoding
const stringContent = data.toString()
// Converts the string back to a buffer using the same encoding
const newData = Buffer.from(stringContent)
// We expect the values to be equal...
console.log(data.equals(newData)) // -> false
I don't understand in what step of the process the bytes are being changed...
I already spent sooo much time trying to figure this out, without any result... If someone can help me understand what part I'm missing out, it would be really awesome!
A .docXfile is not a UTF-8 string (it's a binary ZIP file) so when you read it into a Buffer object and then call .toString() on it, you're assuming it is already encoding as UTF-8 in the buffer and you want to now move it into a Javascript string. That's not what you have. Your binary data will likely encounter things that are invalid in UTF-8 and those will be discarded or coerced into valid UTF-8, causing an irreversible change.
What Buffer.toString() does is take a Buffer that is ALREADY encoded in UTF-8 and puts it into a Javascript string. See this comment in the doc,
If encoding is 'utf8' and a byte sequence in the input is not valid UTF-8, then each invalid byte is replaced with the replacement character U+FFFD.
So, the code you show in your question is wrongly assuming that Buffer.toString() takes binary data and reversibly encodes it as a UTF8 string. That is not what it does and that's why it doesn't do what you are expecting.
Your question doesn't describe what you're actually trying to accomplish. If you want to do something useful with the .docX file, you probably need to actually parse it from it's binary ZIP file form into the actual components of the file in their appropriate format.
Now that you explain you're trying to store it in localStorage, then you need to encode the binary into a string format. One such popular option is Base64 though it isn't super efficient (size wise), but it is better than many others. See Binary Data in JSON String. Something better than Base64 for prior discussion on this topic. Ignore the notes about compression in that other answer because your data is already ZIP compressed.
I have two encoded strings that used same encoding method but i don't know what type it is.
I have tried using base64 decode but it didn't work.
This is the first encoded string I have 3qpY0Vw86MZykGfqc7jnVg==
This is the second encoded string I have nB6dtl3iA5IE1Z+g9SpBrw==
They are using same encoding method.
I want to know what type of encoding that used in that strings. Also I want to know how to decode it.
Those base64 payload may be containing something else than a string, like a raw binary, an image, a ciphered payload, etc. that can't be displayed as text.
base64 is not exclusively used to encode text.
For example to save to a file:
$ printf %s 'iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAAMfUlEQVR4Xu1bC3BU1Rn+7mN3E8IjEiAY3iQxIA8bKiJSRUofjLZKx0cf6mgfap3O6NjptNNqW6vjYDt2+pip09ZXqXa01amIoqJTpVYIijYIpFEgBAMkhEB4JCG7e/fe2+8/ezdsHhYq7t7d5H6ZO3tz7tm7e//vnO9/nLOaSyCAb9C91wA+ISDAZwQE+IyAAJ8REOAzAgJ8RkCAzwgI8BkBAT4jIMBnBAT4jIAAnzHoCbCbt8La+CicQ41eS25hUBOQ+M9LiK++A7G1K5DY9Be4iZh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XoYpbveR5SWlmLO3NOrNMoscVq3JxdS2hoYar6V/BlSrEutEUhdR0oVso6QIkRe1fegHOljKhH+4r0wp52QoNbWVrxXXw/Lsk4QwPPyykpUVFSo/zOFvCNgIMhWROfgLrgHG5RsOYcaODNIhPxIjzNEESS5BR20cfYyhBl+GiVTvXcHBGQEzqHdsPfXq58iqe0oR1vgHm1WRbjwhbf0KrwNaQLUipasRkkf7+FPGyI9IkF6iKc8p+N2ju6He2A7NFmiLO2t60OaAOdQExK1f1VbRJTRMgW5N6Mpc9Yl/YpvQ5oAu/EtxJ68MfljO+PkWfDpQCKmyGUrEL74Vq8lCT8JGDheyyZkZMrabGS4qulk9AgXqaXKXIL/BAxx5AABlCcpG0iWKiWIDB7qcySTziH4T4Ds2xzByGTUhIwfWvEkJXW5BP/DUNnJ3N7EgcnR6TnAjIGfoY0qU1sZ0xEkYj5jaEdBQxwBAT4jqwToH/KjCr9hmCd+oJdtZNUHRCIRFBcXqwWbXIF8v2g0is7OTvW9su0DskKAIPUxGfi400bqOwqyTUDWNCH1YClSculIIf08W8iqKPd98Fw7/EBGCBCREamRQ3Q1L48sSWXGfMDGmhrfRtXHAdkpMb28HOU8MomMEBDg1JGbgfkQQkCAzwgI8BkBAT4jIMBnBAT4jIAAnxEQ4DMCAnxGQIDPCAjwGQEBPiMgwGcEBPiMgACfERDgMwICfEZAgM8ICPAZAQG+Avgv4WYH0htgNTQAAAAASUVORK5CYII=' | base64 -d > stackoverflow.png
According to MIME base64 encoding specified in rfc2045, the base64 encoded data must be split in lines of at most 76 characters.
When decoding, all characters not belonging to the base64 alphabet must ne ignored.
How do we determine the end of MIME base64 encoded data ?
When you've found the start of a base64 encoded object, it should always be possible to find the end without decoding it. Examples:
You might have an email message whose top-level encoding is base64. In that case, the end of the base64 stuff is the end of the body. The end of the body is recognized not by any internal structure, but by the lone . at the end of the SMTP DATA.
If you're reading an email message from an mbox file instead of receiving it via SMTP, the mbox format is responsible for telling you where the end of the message is.
If you have a multipart email body with one part base64, you can scan for the multipart boundary first to find the end of the body part, then pass the whole body part to the base64 decoder.
Similarly, if you have an RFC2047-encoded header with base64, you can find the terminating =? first, then pass the encoded portion to the base64 decoder.
Because the terminators are already identified before base64 decoding begins, the decoder never sees the terminator, so the rule "characters not belonging to the base64 alphabet" is not relevant.
The 2 steps of finding the end of the base64 data and decoding can be combined into a single loop over the input, for efficiency. But conceptually they are separate.
I copy and paste a text from the web that is base64 encoded to this site http://www.motobit.com/util/base64-decoder-encoder.asp ,
but it gives a strange result , it look like a garbled.
May i ask ....how can i decode the text correctly , thank you.
nUł"˘ÂUÓ"…F˙i+Şž›‘Ş˘éăŁqëKĄ®qâ %˘ dŞn‘ĄŐňŢ^{łcąWq\)ńÂÔ€
Here is the base64 encoded text
blWzIh+iwgYbVdODDyKFRv9pFCuqnpuRqqLp46Nx60ulrnHioCWiIARk-qm6RpdUB8t5ee7NjG7lXcVwp8cLUg==