public static byte[] encryptMySQLPassword(String password,byte[] seed){
  if (password == null || password.equals("")) {
    return new byte[0];
  }
  MessageDigest digest=null;
  try {
    digest=MessageDigest.getInstance("SHA-1");
  }
 catch (  NoSuchAlgorithmException e) {
    logger.error("Cannot encrypt password",e);
    return new byte[0];
  }
  byte[] stage1_hash=digest.digest(password.getBytes());
  digest.reset();
  byte[] sha1_stage1=digest.digest(stage1_hash);
  digest.reset();
  digest.update(seed);
  digest.update(sha1_stage1);
  byte[] finalSha1=digest.digest();
  byte[] token=new byte[finalSha1.length];
  for (int i=0; i < finalSha1.length; i++) {
    token[i]=(byte)(stage1_hash[i] ^ finalSha1[i]);
  }
  return token;
}

public static byte [ ] encryptMySQLPassword ( String password , byte [ ] seed ) { if ( password == null || password . equals ( "" ) ) { return new byte [ 0 ] ; } MessageDigest digest = null ; try { digest = MessageDigest . getInstance ( "SHA-1" ) ; } catch ( NoSuchAlgorithmException e ) { logger . error ( "Cannot encrypt password" , e ) ; return new byte [ 0 ] ; } byte [ ] stage1_hash = digest . digest ( password . getBytes ( ) ) ; digest . reset ( ) ; byte [ ] sha1_stage1 = digest . digest ( stage1_hash ) ; digest . reset ( ) ; digest . update ( seed ) ; digest . update ( sha1_stage1 ) ; byte [ ] finalSha1 = digest . digest ( ) ; byte [ ] token = new byte [ finalSha1 . length ] ; for ( int i = 0 ; i < finalSha1 . length ; i ++ ) { token [ i ] = ( byte ) ( stage1_hash [ i ] ^ finalSha1 [ i ] ) ; } return token ; }
do a mysql specific encryption of the given password < br > algorithm is : < br > stage1_hash = sha1 ( password ) < br > token = sha1 ( scramble + sha1 ( stage1_hash ) ) xor stage1_hash
