Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Base64 decode in C# or Java

Tags:

java

c#

base64

I have a Base64-encoded object with the following header:

application/x-xfdl;content-encoding="asc-gzip"

What is the best way to proceed in decoding the object? Do I need to strip the first line? Also, if I turn it into a byte array (byte[]), how do I un-gzip it?

Thanks!


I think I misspoke initially. By saying the header was

application/x-xfdl;content-encoding="asc-gzip"

I meant this was the first line of the file. So, in order to use the Java or C# libraries to decode the file, does this line need to be stripped?

If so, what would be the simplest way to strip the first line?

like image 722
Jason Avatar asked Jul 12 '26 00:07

Jason


1 Answers

To decode the Base64 content in C# you can use the Convert Class static methods.

byte[] bytes = Convert.FromBase64String(base64Data);

You can also use the GZipStream Class to help deal with the GZipped stream.

Another option is SharpZipLib. This will allow you to extract the original data from the compressed data.

like image 106
scptre Avatar answered Jul 13 '26 14:07

scptre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!