08-28-2012 07:09 PM
Can anyone provide me with an example of using the BB APIs to derive a key from a password and a salt using PBKDF2 (i.e. RFC2898) with SHA1 or SHA256 as the PRF. I'm sure this functionality is somewhere in the SDK but I can't seem to find it.
Thanks very much.
09-10-2012 01:23 PM
I managed to figure it out. For anyone else who needs this - using SHA-1 - the following will do the trick:
public byte deriveUsingPBKDF2(byte key,
byte result = null;
PKCS5KDF2PseudoRandomSource kdf =
new PKCS5KDF2PseudoRandomSource(key, salt, iterations);
result = kdf.getBytes(resultSize);
catch( Exception e )
System.out.println("deriveUsingPBKDF2 exception: " + e.toString());
result = null;
02-27-2013 07:32 AM
I wanted to encrypt my data using PBKDF2 With Hmac SHA1. PBKDF2 encryption you explained but still im not able to generate the required key. can you help me in that.
Please find the equivalent java code below:
byte saltBytes = new byte;
SecureRandom rnd = new SecureRandom();
* Generate random salt
factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1")
KeySpec spec = new PBEKeySpec(charArray, saltBytes, NUMBER_OF_ITERATIONS, KEY_SIZE_TO_USE);
secretKey = factory.generateSecret(spec);
Please help me out.