private static String encode_base64(final byte d[],final int len) throws IllegalArgumentException {
  int off=0;
  final StringBuffer rs=new StringBuffer();
  int c1, c2;
  if (len <= 0 || len > d.length) {
    throw new IllegalArgumentException("Invalid len");
  }
  while (off < len) {
    c1=d[off++] & 0xff;
    rs.append(base64_code[c1 >> 2 & 0x3f]);
    c1=(c1 & 0x03) << 4;
    if (off >= len) {
      rs.append(base64_code[c1 & 0x3f]);
      break;
    }
    c2=d[off++] & 0xff;
    c1|=c2 >> 4 & 0x0f;
    rs.append(base64_code[c1 & 0x3f]);
    c1=(c2 & 0x0f) << 2;
    if (off >= len) {
      rs.append(base64_code[c1 & 0x3f]);
      break;
    }
    c2=d[off++] & 0xff;
    c1|=c2 >> 6 & 0x03;
    rs.append(base64_code[c1 & 0x3f]);
    rs.append(base64_code[c2 & 0x3f]);
  }
  return rs.toString();
}

private static String encode_base64 ( final byte d [ ] , final int len ) throws IllegalArgumentException { int off = 0 ; final StringBuffer rs = new StringBuffer ( ) ; int c1 , c2 ; if ( len <= 0 || len > d . length ) { throw new IllegalArgumentException ( "Invalid len" ) ; } while ( off < len ) { c1 = d [ off ++ ] & 0xff ; rs . append ( base64_code [ c1 > > 2 & 0x3f ] ) ; c1 = ( c1 & 0x03 ) << 4 ; if ( off >= len ) { rs . append ( base64_code [ c1 & 0x3f ] ) ; break ; } c2 = d [ off ++ ] & 0xff ; c1 |= c2 > > 4 & 0x0f ; rs . append ( base64_code [ c1 & 0x3f ] ) ; c1 = ( c2 & 0x0f ) << 2 ; if ( off >= len ) { rs . append ( base64_code [ c1 & 0x3f ] ) ; break ; } c2 = d [ off ++ ] & 0xff ; c1 |= c2 > > 6 & 0x03 ; rs . append ( base64_code [ c1 & 0x3f ] ) ; rs . append ( base64_code [ c2 & 0x3f ] ) ; } return rs . toString ( ) ; }
encode a byte array using bcrypt ' s slightly - modified base64 encoding scheme . note that this is * not * compatible with the standard mime - base64 encoding .
