Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert base64 String to Byte code in java [duplicate]

Tags:

java

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.

like image 483
Madhuri Avatar asked Jul 13 '12 06:07

Madhuri


2 Answers

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());
like image 194
tomi Avatar answered Oct 11 '22 19:10

tomi


import sun.misc.BASE64Decoder;

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

Where imageData is String containing Base64 data.

like image 2
Taha Avatar answered Oct 11 '22 19:10

Taha