6

Possible Duplicate:
Decode Base64 data in java

I am working on java profile, I want to know , how to convert the base64 string to byte array. could any one please provide code & it will be help fule to me.

Community
  • 1
  • 1
Madhuri
  • 187
  • 1
  • 4
  • 10

2 Answers2

14

You can also use Apache Commons Codec (http://commons.apache.org/codec/)

String example = "SGVsbG8gV29ybGQ="
byte[] decoded = org.apache.commons.codec.binary.Base64.decodeBase64(example .getBytes());
tomi
  • 706
  • 1
  • 6
  • 21
2
import sun.misc.BASE64Decoder;

BASE64Decoder decoder = new BASE64Decoder();
byte[] imageByte = decoder.decodeBuffer(imageData);

Where imageData is String containing Base64 data.

Taha
  • 1,086
  • 1
  • 10
  • 20