File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
main/java/org/bouncycastle/crypto/generators
test/java/org/bouncycastle/crypto/test Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -309,7 +309,7 @@ private static boolean doCheckPassword(
309309 boolean isEqual = sLength == newBcryptString .length ();
310310 for (int i = 0 ; i != sLength ; i ++)
311311 {
312- isEqual &= (bcryptString .indexOf (i ) == newBcryptString .indexOf (i ));
312+ isEqual &= (bcryptString .charAt (i ) == newBcryptString .charAt (i ));
313313 }
314314 return isEqual ;
315315 }
Original file line number Diff line number Diff line change 11package org .bouncycastle .crypto .test ;
22
3+ import java .security .SecureRandom ;
4+
35import org .bouncycastle .crypto .generators .OpenBSDBCrypt ;
46import org .bouncycastle .util .Strings ;
57import org .bouncycastle .util .test .SimpleTest ;
@@ -199,6 +201,24 @@ public void performTest()
199201 fail ("twoBVec mismatch: " + "[" + i + "] " + password );
200202 }
201203 }
204+
205+
206+ int costFactor = 4 ;
207+ SecureRandom random = new SecureRandom ();
208+ salt = new byte [16 ];
209+ for (int i = 0 ; i < 1000 ; i ++)
210+ {
211+ random .nextBytes (salt );
212+ final String tokenString = OpenBSDBCrypt
213+ .generate ("test-token" .toCharArray (), salt , costFactor );
214+
215+ isTrue (OpenBSDBCrypt .checkPassword (tokenString , "test-token" .toCharArray ()));
216+ isTrue (!OpenBSDBCrypt .checkPassword (tokenString , "wrong-token" .toCharArray ()));
217+ }
202218 }
219+
220+
221+
222+
203223}
204224
You can’t perform that action at this time.
0 commit comments