24 June, 2008

String from base64 string, to base64 string in Java

This is very simple:


import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

...

public static String fromBase64(String in) throws IOException {
return new String(new BASE64Decoder().decodeBuffer(in));
}

public static String toBase64(String in) {
return new String(new BASE64Encoder().encodeBuffer(in.getBytes()));
}

No comments: