private static final byte[] convert(byte[] value,Direction direction,String secret,Authenticator ra) throws IOException {
  MessageDigest md5=null;
  try {
    md5=MessageDigest.getInstance("MD5");
  }
 catch (  final NoSuchAlgorithmException e) {
    throw new IOException(e.getMessage());
  }
  md5.update(secret.getBytes(StandardCharsets.UTF_8));
  md5.update(ra.getOctets());
  byte[] sum=md5.digest();
  final byte[] up=value;
  int oglen=(up.length / 16);
  if (up.length % 16 != 0) {
    oglen=oglen + 1;
  }
  final byte[] ret=new byte[oglen * 16];
  for (int i=0; i < ret.length; i++) {
    if ((i % 16) == 0) {
      md5.reset();
      md5.update(secret.getBytes(StandardCharsets.UTF_8));
    }
    if (i < up.length) {
      ret[i]=(byte)(sum[i % 16] ^ up[i]);
    }
 else {
      ret[i]=(byte)(sum[i % 16] ^ 0);
    }
    if (direction == Direction.ENCRYPT) {
      md5.update(ret[i]);
    }
 else {
      md5.update(up[i]);
    }
    if ((i % 16) == 15) {
      sum=md5.digest();
    }
  }
  return ret;
}

private static final byte [ ] convert ( byte [ ] value , Direction direction , String secret , Authenticator ra ) throws IOException { MessageDigest md5 = null ; try { md5 = MessageDigest . getInstance ( "MD5" ) ; } catch ( final NoSuchAlgorithmException e ) { throw new IOException ( e . getMessage ( ) ) ; } md5 . update ( secret . getBytes ( StandardCharsets . UTF_8 ) ) ; md5 . update ( ra . getOctets ( ) ) ; byte [ ] sum = md5 . digest ( ) ; final byte [ ] up = value ; int oglen = ( up . length / 16 ) ; if ( up . length % 16 != 0 ) { oglen = oglen + 1 ; } final byte [ ] ret = new byte [ oglen * 16 ] ; for ( int i = 0 ; i < ret . length ; i ++ ) { if ( ( i % 16 ) == 0 ) { md5 . reset ( ) ; md5 . update ( secret . getBytes ( StandardCharsets . UTF_8 ) ) ; } if ( i < up . length ) { ret [ i ] = ( byte ) ( sum [ i % 16 ] ^ up [ i ] ) ; } else { ret [ i ] = ( byte ) ( sum [ i % 16 ] ^ 0 ) ; } if ( direction == Direction . ENCRYPT ) { md5 . update ( ret [ i ] ) ; } else { md5 . update ( up [ i ] ) ; } if ( ( i % 16 ) == 15 ) { sum = md5 . digest ( ) ; } } return ret ; }
converts the plain text password to cipher text , or cipher text to plain text according following the algorithm specified in section 5 . 2 of rfc 2865 .
