Open bobmulder opened 9 years ago
Probably an invalid string that you are trying to decode. Can you paste the string?
Would not like that to do, because it contains privately data ;). However, I've tried to decode it myself and online and it worked perfectly...
I can't really figure out what the problem is unless I can see what's being de/encoded. Can you anonymise it at all, or try encoding/decoding substrings to narrow down which characters might be the problem?
Thanks
I will try when I got time. It's fixed for now by using the javascript build in decoder. However, it doesn't look clean ;)
I dug into the code, and this is the offending conditional.
if (imax % 4 != 0) {
throw "Cannot decode base64";
}
Commenting it out resolves the issue. For instance the following encoded string: "eyJlbWFpbCI6InJ5YW4udGhvbXBzb25AcGhlcm9jaXR5LmNvbSIsIm5hbWUiOiJSeWFuIFRob21wc29uIn0" is decoded into {"email":"ryan.thompson@pherocity.com","name":"Ryan Thompson"}. Results are matched on https://www.base64decode.org. Now the interesting thing, using your encode of that same string results in that same string with a � character at the end when decoded on the mentioned site.
Initial encoding was done by the ruby 'jwt' gem.
I am also running into this issue decoding base64 strings encoded in nginx (via lua).
It seems to me that it's a padding issue. Because of the bit mismatch (6 bits vs 8 bits) padding is often added to the end of a base64 string, this is often represented with a trailing '=' or '=='.
Padding is not required according to the base64 spec, but this library seems to require it. Strings encoded without padding therefore fail.
+1
+1 padding appears to be required
+1
+1
@ninjatronic This is still happening. I'm trying to convert
eyJmaWVsZE5hbWVzIjpbXSwib3JkZXJCeSI6eyJuYW1lIjpudWxsLCJkaXJlY3Rpb24iOm51bGx9LCJwcmVkaWNhdGVzIjpbeyJhdHRyaWJ1dGUiOm51bGwsImNvbXBhcmlzb24iOiJoYXZlX3RhZyIsInZhbHVlIjoidGFnXzM2MjZiMWVjOWNmZjQ0MzBhNTRjZGQ5YjMxNTM3MjAxIn1dfQ
and it throws Cannot decode base64
error.
It works fine online with https://www.base64decode.org/
{"fieldNames":[],"orderBy":{"name":null,"direction":null},"predicates":[{"attribute":null,"comparison":"have_tag","value":"tag_3626b1ec9cff4430a54cdd9b31537201"}]}
Sorry everyone, I have been away from the internet for a long time.
I am still about 1500km from my computer, probably for at least a year. If someone can verify the linked pull request fixed the issue I will merge it.
Thanks
@ninjatronic I have fixed the merge conflicts with my branch and added some encode/decode tests as well.
If you would like to test these on your current master (or perhaps someone else can) you can copy tests.js to the project root and npm install tape
and run the tests with node tests
.
The final test will fail on the current master branch, it passes on the PR referenced above.
@ninjatronic the above pull request fixed the issue. Please merge the pull request, when ever you got the chance.
+1
Getting the error
Cannot decode base64
. Any possible reasons?