I tried to decode a following base64 string in C#:
PGlmcmFtZSBzcmM9Imh0dHA6Ly9lbWJlZC5yZWR0dWJlLmNvbS8\/aWQ9Mzg1NjAmYmdjb2x
vcj0wMDAwMDAiIGZyYW1lYm9yZGVyPSIwIiB3aWR0aD0iNDM0IiBoZWlnaHQ9IjM0NCIgc2Nyb2xsaW5n
PSJubyIgYWxsb3dmdWxsc2NyZWVuPjwvaWZyYW1lPg==
But i'm getting an error:
The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
Even if i remove last
=
in the string above but still the same error.
Here is the code i use:
byte[] decodedBytes = Convert.FromBase64String(embedCode);
string decodedText = Encoding.UTF8.GetString(decodedBytes);
Why is that?
Thank you.
the correct Base64String is:
PGlmcmFtZSBzcmM9Imh0dHA6Ly9lbWJlZC5yZWR0dWJlLmNvbS8/aWQ9Mzg1NjAmYmdjb2x
vcj0wMDAwMDAiIGZyYW1lYm9yZGVyPSIwIiB3aWR0aD0iNDM0IiBoZWlnaHQ9IjM0NCIgc2Nyb2xsaW5n
PSJubyIgYWxsb3dmdWxsc2NyZWVuPjwvaWZyYW1lPg==
Well this is not a valid Base64String. Base64String can not have \ character. remove this character and it will work
Related
𝐀 = (\ud835\udc00) in UTF16
How do I do this conversion in C#?
The following code doesn't allow me to enter the character above. It throws the error "Too many characters in character literal" I guess it's because the char is multi point.
string hex = ((int)'𝐀').ToString("X4");
string hex = ((int)'A').ToString("X4");// This works
A help would be much appreciated!
I am trying to decode the following Base64 string that i'm getting from a url like so:
string msgFromUrl = "j3oaCbiwIfZF1QFa%2FHkMaW5lVpnOMBsA5wYI";
byte[] data = Convert.FromBase64String(msgFromUrl);
string decoded = Encoding.UTF8.GetString(data);
Console.WriteLine(decoded);
I am getting an error on the string that i need to decode. The error i'm getting is:
The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
I have realised that there is a percentage symbol in the string and when i try remove it i come short of the valid length of Base64 char. Since i'm retrieving this from a url, could there be anything hidden or do i have to do more than i have done in order to decode the encoded string?
Thank you .
I'm trying to remove a dependence on System.Web.dll from a Web API project, but have stumbled on a call to HttpServerUtility.UrlTokenEncode(byte[] input) (and its corresponding decode method) that I don't know what to replace with to ensure backwards compatibility. The documentation says that this method
Encodes a byte array into its equivalent string representation using base 64 digits, which is usable for transmission on the URL.
I tried substituting with Convert.ToBase64String(byte[] input) (and its corresponding decode method), which is very similarly described in the docs:
Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with base-64 digits.
However, they don't seem to be entirely equivalent; when using Convert.FromBase64String(string input) to decode a string encoded with HttpServerUtility, I get an exception stating
The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
What is the difference between these two conversion utilities? What's the correct way to remove this dependence on System.Web.HttpServerUtility?
Some users have suggested that this is a duplicate of this one, but I disagree. That question is about base-64-encoding a string in a url-safe manner in general, but I need to reproduce the exact behavior of HttpServerUtility but without a dependency on System.Web.
I took DGibbs on their word and Used the Source. It turns out the following happens in the HttpServerUtility methods:
Encoding to Base64
Use System.Convert to convert the input to Base64.
Replace + by - and / by _. Example: Foo+bar/=== becomes Foo-bar_===.
Replace any number of = at the end of the string, with an integer denoting how many they were. Example: Foo-bar_=== becomes Foo-bar_3.
Decoding from Base64
Replace the digit at the end of the string by the same number of = signs. Example: Foo-bar_3 becomes Foo-bar_===.
Replace - by + and _ by /. Example: Foo-bar_=== becomes Foo+bar/===.
Use System.Convert to decode the preprocessed input from Base64.
HttpServerUtility.UrlTokenEncode(byte[] input) will encode a URL safe Base64 string. In Base64 +, / and = characters are valid, but they are not URL safe, this method will replace these characters whereas the Convert.ToBase64String(byte[] input) will not. You can probably drop the reference and do it yourself.
Usually, '+' is replaced with '-' and '/' with '_' padding '=' is just removed.
Accepted answer here gives a code example: How to achieve Base64 URL safe encoding in C#?
How do I get the Image Path from below base 64 string?
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxQT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aNsbSbm28npJ50BZoAQAgBACAEBr9ZsXRSyGR8IL3G5IfI0E85ytcBfuQCo9jqIbqdh7czvzEoDzHwkU3F4rVN/nDvSaCfXdAa0gBACAEAIAQAgMXQGWi+4X7NUBJjw6Z3kxSnsjcfcgLCn2UrX+TTSn7NvagLSl4NcSfupXjt/tdAWtNwN4k7exje1/uQFpT8BVYfKmib6/YUBa03AG795VD7LfiEBa0vANTDy6iV3cLeqyAtafgTw5vlCR32yPVqgLWn4K8MZ/DB39RugLWm2JoI/IpYh3ICyiwanb5MMQ+w34ICVHA1vktaOwAIBxACAEAIAQAgBACAEAIAQAgBACAEAIDhPDPsBUS1XyqmYZGvAD2jeCNxHN1dw38wHO6fYDEXnk0snbyfigLan4I8Tf+6a3+okf6UBa03AfXO8p8bO8H3oC1puASX95UsHY0oC0puASEeXUyHsA+CAtafgPoB5TpX/aI9hQFtTcEeGM/c5v6jf2oC0peD/Do/JpYvD4IC0g2fpWeTBEPsA+1ATI6ONvkxsHY1o9yAeAQGUAIAQAgBACAEAIAQAgBACAEAIAQAgBACAEAID/2Q==
I tried doing it this way:
byte[] data = Convert.FromBase64String(_model.Image_Array[i]);
fileName = Path.GetFileName(Encoding.UTF8.GetString(data));
path = Path.Combine(Server.MapPath("~/Images/Product/"), fileName);
file[i].SaveAs(path);
But it is throwing up below error:
The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
The following line of code runs fine in IIS Express:
Convert.FromBase64String("dmVoaWNsZUlkPTE0MTM=??");
But when run on my local IIS 8 server, it throws the following exception:
System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
Why is this happening?
The last two characters "??" are not valid in a base 64 string.
Have a read here: https://en.wikipedia.org/wiki/Base64
The string should end in an alphanumeric character or be padded with one or more = characters.
Edit — Decoding the string without the ? characters returns "vehicleId=1413", so I guess it's just a case of removing them.