question: public static byte [ ] encryptPassword ( final String password , final byte [ ] seed ) throws NoSuchAlgorithmException { if ( password == null || password . equals ( "" ) ) { return new byte [ 0 ] ; } final MessageDigest messageDigest = MessageDigest . getInstance ( "SHA-1" ) ; final byte [ ] stage1 = messageDigest . digest ( password . getBytes ( ) ) ; messageDigest . reset ( ) ; final byte [ ] stage2 = messageDigest . digest ( stage1 ) ; messageDigest . reset ( ) ; messageDigest . update ( seed ) ; messageDigest . update ( stage2 ) ; final byte [ ] digest = messageDigest . digest ( ) ; final byte [ ] returnBytes = new byte [ digest . length ] ; for ( int i = 0 ; i < digest . length ; i ++ ) { returnBytes [ i ] = ( byte ) ( stage1 [ i ] ^ digest [ i ] ) ; } return returnBytes ; }
target:  encrypts a password <p> protocol for authentication is like this: 1. mysql server sends a random array of bytes (the seed) 2. client makes a sha1 digest of the password 3. client hashes the output of 2 4. client digests the seed 5. client updates the digest with the output from 3 6. an xor of the output of 5 and 2 is sent to server 7. server does the same thing and verifies that the scrambled passwords match