MySQLPasswordEncryptor { public static byte[] encryptWithMySQL41(final byte[] password, final byte[] seed) throws NoSuchAlgorithmException { MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); byte[] passwordSha1 = messageDigest.digest(password); byte[] concatSeed = concatSeed(messageDigest, seed, messageDigest.digest(passwordSha1)); return xorPassword(passwordSha1, concatSeed); }  static byte[] encryptWithMySQL41(final byte[] password, final byte[] seed);  }
@Test public void assertEncryptWithMySQL41() throws NoSuchAlgorithmException { byte[] passwordBytes = "password".getBytes(); byte[] seed = getRandomSeed(); assertThat(MySQLPasswordEncryptor.encryptWithMySQL41(passwordBytes, seed), is(getExpectedPassword())); }