0

I am doing:

SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA512") );
SecretKey key            = factory.generateSecret( new PBEKeySpec(password.toCharArray(), salt, iterations, keyLength) ); 

and am wondering particuraliy about:

new PBEKeySpec(password.toCharArray(), salt, iterations, keyLength)

how many iterations are "enough"?

I have seen examples using 65000, which seems to be alot. Is that neccessary? What are the consequences of having such a high iteration?

mjs
  • 21,431
  • 31
  • 118
  • 200
  • This still applies: [Recommended # of iterations when using PKBDF2-SHA256?](http://security.stackexchange.com/questions/3959/recommended-of-iterations-when-using-pkbdf2-sha256) – Artjom B. Apr 03 '15 at 12:34
  • @ArtjomB. Only problem with that article is that it doesn't give one single example of what a good value is. As much as you computer can handle is not a good answer. I want to know if 1000 is good enough or what range I can feel secure using. Everytime I run my static void main to test it takes different amount of time, sometimes instantly for 30 000, sometimes it takes forever.. even when the jvm shuts down and I restart the application, and lower the iteration count. There is no good way to test this it seems. Consequences is that it is hard to change once selected. A rehashing of all pass.. – mjs Apr 03 '15 at 12:40
  • passwords would be required to make a change later on. – mjs Apr 03 '15 at 12:41
  • 2
    1. If this is for passwords, you can save the iteration count alongside the salt and hash and increase the default for new users or changed passwords. 2. *Everytime I run my static void main to test it takes different amount of time* That's always a problem with java. It's hard to create a correct benchmark: see [here](http://stackoverflow.com/questions/504103/how-do-i-write-a-correct-micro-benchmark-in-java). – Artjom B. Apr 03 '15 at 12:46
  • @ArtjomB. Yes, I might be able to do that, but won't that reveal the iteration count which might otherwise be hard to figure out? Or maybe not? – mjs Apr 03 '15 at 13:38
  • 1
    @ArtjomB. Other tricks are to stack multiple invocations of PBKDF2 so you can upgrade later. You can also run PBKDF2 on the client, as long as you perform at least one additional hash + salt on the server. Note that these ideas are not mine, I basically copied them from CodesInChaos :) – Maarten Bodewes Apr 03 '15 at 13:42
  • I'm voting to close this question as off-topic because the link to the security site applies even if it does not target Java specifically. – Maarten Bodewes Apr 03 '15 at 13:45

0 Answers0