• Post Reply Bookmark Topic Watch Topic
  • New Topic

base64 conversion  RSS feed

 
Kishore Dandu
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to base64 encode a string, convert the output to a string(since the output is byte array), send it as a get parameter and decrypt using base64 on the other end??
 
Ian Darwin
author
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See java.net.URLEncoder.encode(value, "UTF-8"). I'll leave you to guess what the corresponding Decoder class and method are called :-)

Ian
 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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) {
}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!