views:

255

answers:

3

whats happening in this line of code ?

SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");

i specially dont understand getInstance("PBKDF2WithHmacSHA1") part

+5  A: 

This funky looking string defines the secret-key algorithm to be used. It is:

PBKDF2WithHmacSHA1
PBKDF2 With Hmac SHA1
  • the PBKDF2 function (from PKCS#5 version 2.0)
  • which will be using SHA-1 HMAC for its pseudo-random number generator

References:
We find similar algorithm names in Java Crypto Extension Guide Appending A, somehow PKCS5 version 2 may not have been available/documented then (or indeed as suggested by brianegge, may be a matter of export restriction, a common issue with cryptographic items).
The algorithm name does show up in RFC3962 (AES for Kerberos) which may not be the very application you have in mind, but defined, all the same)

mjv
It's a standard name in Java 6.
erickson
+1  A: 

Different distributions of Java contain different crypto. This is due to export restrictions and patents. The line of code is requesting a factory which can create that type of key.

Specifically, PBKDF2WithHmacSHA1 constructs secret keys using the Password-Based Key Derivation Function function found in PKCS5 v2.0.

brianegge
+1  A: 
erickson