1 package org.bouncycastle.jcajce.spec; 2 3 import javax.crypto.spec.PBEKeySpec; 4 5 import org.bouncycastle.asn1.DERNull; 6 import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; 7 import org.bouncycastle.asn1.x509.AlgorithmIdentifier; 8 9 /** 10 * Extension of PBEKeySpec which takes into account the PRF algorithm setting available in PKCS#5 PBKDF2. 11 */ 12 public class PBKDF2KeySpec 13 extends PBEKeySpec 14 { 15 private static final AlgorithmIdentifier defaultPRF = new AlgorithmIdentifier(PKCSObjectIdentifiers.id_hmacWithSHA1, DERNull.INSTANCE); 16 17 private AlgorithmIdentifier prf; 18 19 /** 20 * Base constructor. 21 * 22 * @param password password to use as the seed of the PBE key generator. 23 * @param salt salt to use in the generator, 24 * @param iterationCount iteration count to use in the generator. 25 * @param keySize size of the key to be generated (in bits). 26 * @param prf identifier and parameters for the PRF algorithm to use. 27 */ 28 public PBKDF2KeySpec(char[] password, byte[] salt, int iterationCount, int keySize, AlgorithmIdentifier prf) 29 { 30 super(password, salt, iterationCount, keySize); 31 32 this.prf = prf; 33 } 34 35 /** 36 * Return true if this spec is for the default PRF (HmacSHA1), false otherwise. 37 * 38 * @return true if this spec uses the default PRF, false otherwise. 39 */ 40 public boolean isDefaultPrf() 41 { 42 return defaultPRF.equals(prf); 43 } 44 45 /** 46 * Return an AlgorithmIdentifier representing the PRF. 47 * 48 * @return the PRF's AlgorithmIdentifier. 49 */ 50 public AlgorithmIdentifier getPrf() 51 { 52 return prf; 53 } 54 } 55