@@ -43,6 +43,11 @@ public void testApr1CryptStrings() throws NoSuchAlgorithmException {
4343
4444 @ Test
4545 public void testApr1CryptBytes () throws NoSuchAlgorithmException {
46+ // random salt
47+ byte [] keyBytes = new byte [] { '!' , 'b' , 'c' , '.' };
48+ String hash = Md5Crypt .apr1Crypt (keyBytes );
49+ assertEquals (hash , Md5Crypt .apr1Crypt ("!bc." , hash ));
50+
4651 // An empty Bytearray equals an empty String
4752 assertEquals ("$apr1$foo$P27KyD1htb4EllIPEYhqi0" , Md5Crypt .apr1Crypt (new byte [0 ], "$apr1$foo" ));
4853 // UTF-8 stores \u00e4 "a with diaeresis" as two bytes 0xc3 0xa4.
@@ -60,6 +65,11 @@ public void testApr1CryptExplicitCall() throws NoSuchAlgorithmException {
6065 assertTrue (Md5Crypt .apr1Crypt ("secret" .getBytes (), null ).matches ("^\\ $apr1\\ $[a-zA-Z0-9./]{0,8}\\ $.{1,}$" ));
6166 }
6267
68+ @ Test
69+ public void testApr1LongSalt () throws NoSuchAlgorithmException {
70+ assertEquals ("$apr1$12345678$0lqb/6VUFP8JY/s/jTrIk0" , Md5Crypt .apr1Crypt ("secret" , "12345678901234567890" ));
71+ }
72+
6373 @ Test (expected = NullPointerException .class )
6474 public void testApr1CryptNullData () throws NoSuchAlgorithmException {
6575 Md5Crypt .apr1Crypt ((byte []) null );
@@ -69,4 +79,9 @@ public void testApr1CryptNullData() throws NoSuchAlgorithmException {
6979 public void testApr1CryptWithEmptySalt () throws NoSuchAlgorithmException {
7080 Md5Crypt .apr1Crypt ("secret" .getBytes (), "" );
7181 }
82+
83+ @ Test (expected = IllegalArgumentException .class )
84+ public void testApr1CryptWithInvalidSalt () throws NoSuchAlgorithmException {
85+ Md5Crypt .apr1Crypt (new byte [0 ], "!" );
86+ }
7287}
0 commit comments