Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
3.33/5 (2 votes)
See more:
Hi,
Please does anyone know how I can convert a byte array to base 64 string and from a base 64 string to a byte array in Java
Posted
Updated 12-Jan-11 7:36am
v2
Comments
CPallini 12-Jan-11 15:28pm    
You may also write your own conversion routines, it would be an useful exercise.

1 solution

Google knows all ("java byte array to base64"). Seriously dude, it took me all of 20 seconds to find this using google:

try {
    // Convert a byte array to base64 string
    byte[] buf = new byte[]{0x12, 0x23};
    String s = new sun.misc.BASE64Encoder().encode(buf);

    // Convert base64 string to a byte array
    buf = new sun.misc.BASE64Decoder().decodeBuffer(s);
} catch (IOException e) {
}


EDIT ===============

Why did you mark this as the answer, and then un-mark it?

EDIT AGAIN ==============

Did you have trouble googling how to go back to a byte array from a base64 string? I found a page that has code for going both ways:

http://www.rgagnon.com/javadetails/java-0598.html[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900