2

I have converted image byte array to base64encoded string in Java using

Base64.encodeBase64URLSafeString(baos.toByteArray());

and I am able to decode it back to byte array ans save the image in file which is same as original file . But when I pass the base64 encoded string to the ASP .NET web service , and try to decode using

Convert.FromBase64String(base64String);

I am unable to reproduce the same image . Please suggest me the correct way to decode - an encoded base64 image in java- in C#.

1 Answer 1

5

I'm assuming that you use commons-codec from Apache as Java does not have a class Base64 in the standard API.

You use the wrong method from the class Base64 on the Java side. You have to use

Base64.encodeBase64(baos.toByteArray());

The method you're using is to create base64 in an URL safe manner and not the default base64 encoding.

See also the wikipedia article for the differences.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your reply . I have changed the method to Base64.encodeBase64String(baos.toByteArray()); . Its working now :)
@sulthana If the solution works for you it is nice to accept the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.