1 package org.bouncycastle.jcajce;
2 
3 import javax.crypto.interfaces.PBEKey;
4 
5 import org.bouncycastle.util.Arrays;
6 
7 /**
8  * A password based key for use with PKCS#12 with full PBE parameters.
9  */
10 public class PKCS12KeyWithParameters
11     extends PKCS12Key
12     implements PBEKey
13 {
14     private final byte[] salt;
15     private final int iterationCount;
16 
17     /**
18      * Basic constructor for a password based key with generation parameters.
19      *
20      * @param password password to use.
21      * @param salt salt for generation algorithm
22      * @param iterationCount iteration count for generation algorithm.
23      */
PKCS12KeyWithParameters(char[] password, byte[] salt, int iterationCount)24     public PKCS12KeyWithParameters(char[] password, byte[] salt, int iterationCount)
25     {
26         super(password);
27 
28         this.salt = Arrays.clone(salt);
29         this.iterationCount = iterationCount;
30     }
31 
32 
33     /**
34      * Basic constructor for a password based key with generation parameters, specifying the wrong conversion for
35      * zero length passwords.
36      *
37      * @param password password to use.
38      * @param salt salt for generation algorithm
39      * @param iterationCount iteration count for generation algorithm.
40      * @param useWrongZeroLengthConversion use the incorrect encoding approach (add pad bytes)
41      */
PKCS12KeyWithParameters(char[] password, boolean useWrongZeroLengthConversion, byte[] salt, int iterationCount)42     public PKCS12KeyWithParameters(char[] password, boolean useWrongZeroLengthConversion, byte[] salt, int iterationCount)
43     {
44         super(password, useWrongZeroLengthConversion);
45 
46         this.salt = Arrays.clone(salt);
47         this.iterationCount = iterationCount;
48     }
49 
50     /**
51      * Return the salt to use in the key derivation function.
52      *
53      * @return the salt to use in the KDF.
54      */
getSalt()55     public byte[] getSalt()
56     {
57         return salt;
58     }
59 
60     /**
61      * Return the iteration count to use in the key derivation function.
62      *
63      * @return the iteration count to use in the KDF.
64      */
getIterationCount()65     public int getIterationCount()
66     {
67         return iterationCount;
68     }
69 }
70