-4

I am trying to convert byte array to base64 format in java.
my problem is sun.misc.BASE64Decoder cannot be used? Is there any alternative?

byte[] buf = new byte[] { 0x12, 0x23 };
String s = new sun.misc.BASE64Encoder().encode(buf);
Subin Sebastian
  • 10,870
  • 3
  • 37
  • 42
Jahir
  • 552
  • 4
  • 9
  • 17

2 Answers2

0

I would recommend using this library: MigBase64

Use it like this:

 byte [] buf = new byte[]{0x12, 0x23};
 String s = Base64.encode(buf);
rtheunissen
  • 7,347
  • 5
  • 34
  • 65
0
  1. Base64 is not an encryption technique. It is just an encoding mechanism. If you're looking for enryption you're barking up the wrong tree.

  2. import sun.misc.BASE64Decoder is not a 'header file', it is an import statement. It may not compile if you are using a non-Sun/Oracle JDK. It may give you warnings which you should heed. As you haven't actually said what problem you are having it is impossible to comment further.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Thanks. I import this statement i got a error message is 'Access restriction: The type BASE64Decoder is not accessible due to restriction on required library C:\Program Files\Java\jre6\lib\rt.jar' – Jahir Jun 19 '12 at 07:23
  • @Jahir So (a) adjust your IDE not to treat that as an error, or (b) use another Base-64 encoder such as the Apache one. – user207421 Jun 19 '12 at 07:31