forked from OWASP/CheatSheetSeries
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix iteration_count number typo (OWASP#100)
- Fix number typo - Add details about the non time constant algorithm that will produce different result on different hardware - Add the code example provided in the issue to test iteration count on your own hardware
- Loading branch information
1 parent
90edc2c
commit c68280f
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
assets/Password_Storage_Cheat_Sheet_Test_PBKDF2_Iterations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import javax.crypto.SecretKeyFactory; | ||
import javax.crypto.spec.PBEKeySpec; | ||
import java.security.SecureRandom; | ||
|
||
// PLEASE RENAME THIS FILE TO PBKDF2ItEval.java BEFORE COMPILING. | ||
public class PBKDF2ItEval { | ||
|
||
public static void main(String[] args) throws Exception { | ||
//Initialization | ||
SecureRandom rnd = new SecureRandom(); | ||
byte[] salt = new byte[64]; | ||
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA512"); | ||
char[] password = "mypassword".toCharArray(); | ||
//Test for 10.000 iterations | ||
rnd.nextBytes(salt); | ||
PBEKeySpec spec = new PBEKeySpec(password, salt, 10000, 256); | ||
long start = System.currentTimeMillis(); | ||
skf.generateSecret(spec); | ||
System.out.printf("Computation time is %s milliseconds for 10.000 iterations with a key size of 256 bits\n", (System.currentTimeMillis() - start)); | ||
//Test for 100.000 iterations | ||
rnd.nextBytes(salt); | ||
spec = new PBEKeySpec(password, salt, 100000, 256); | ||
start = System.currentTimeMillis(); | ||
skf.generateSecret(spec); | ||
System.out.printf("Computation time is %s milliseconds for 100.000 iterations with a key size of 256 bits\n", (System.currentTimeMillis() - start)); | ||
//Test for 500.000 iterations | ||
rnd.nextBytes(salt); | ||
spec = new PBEKeySpec(password, salt, 500000, 256); | ||
start = System.currentTimeMillis(); | ||
skf.generateSecret(spec); | ||
System.out.printf("Computation time is %s milliseconds for 500.000 iterations with a key size of 256 bits\n", (System.currentTimeMillis() - start)); | ||
//Test for 1.000.000 iterations | ||
rnd.nextBytes(salt); | ||
spec = new PBEKeySpec(password, salt, 1000000, 256); | ||
start = System.currentTimeMillis(); | ||
skf.generateSecret(spec); | ||
System.out.printf("Computation time is %s milliseconds for 1.000.000 iterations with a key size of 256 bits\n", (System.currentTimeMillis() - start)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters