rust-base64
rust-base64 copied to clipboard
Check if the data is a valid base64 encoded
I have a project with stream of strings but not sure which one is base64 encoded, I tried to use .decode method and only get successful results but at the end decoded strings are mostly invalid.
Is there a good way to check if a data is a valid base64?
You can try decoding them and see if you get an error. Even then, it's quite possible to have a random string that happens to decode but wasn't intended to be base64. There's also the question of what alphabet is in use, etc.
The same problem exists in other systems as well, like trying to guess the character encoding of text. You can use heuristics to sort of do it sometimes, but there's really no reliable way.