public static ByteArrayOutputStream encode(String plaintext) throws IOException, MessagingException {
  ByteArrayOutputStream out=new ByteArrayOutputStream();
  byte[] in=plaintext.getBytes();
  ByteArrayOutputStream inStream=new ByteArrayOutputStream();
  inStream.write(in,0,in.length);
  if ((in.length % 3) == 1) {
    inStream.write(0);
    inStream.write(0);
  }
 else   if ((in.length % 3) == 2) {
    inStream.write(0);
  }
  inStream.writeTo(MimeUtility.encode(out,"base64"));
  return out;
}

public static ByteArrayOutputStream encode ( String plaintext ) throws IOException , MessagingException { ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; byte [ ] in = plaintext . getBytes ( ) ; ByteArrayOutputStream inStream = new ByteArrayOutputStream ( ) ; inStream . write ( in , 0 , in . length ) ; if ( ( in . length % 3 ) == 1 ) { inStream . write ( 0 ) ; inStream . write ( 0 ) ; } else if ( ( in . length % 3 ) == 2 ) { inStream . write ( 0 ) ; } inStream . writeTo ( MimeUtility . encode ( out , "base64" ) ) ; return out ; }
encode string to base64
