1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18package javax.crypto.spec;
19
20import java.security.spec.AlgorithmParameterSpec;
21
22/**
23 * The algorithm parameter specification for a <i>password based encryption</i>
24 * algorithm.
25 * <p>
26 * Password based encryption is described in <a
27 * href="http://www.ietf.org/rfc/rfc2898.txt">PKCS #5</a>.
28 *
29 */
30public class PBEParameterSpec implements AlgorithmParameterSpec {
31
32    private final byte[] salt;
33    private final int iterationCount;
34
35    /**
36     * Creates a new <code>PBEParameterSpec</code> with the specified salt and
37     * iteration count.
38     *
39     * @param salt
40     *            the salt.
41     * @param iterationCount
42     *            the iteration count.
43     * @throws NullPointerException
44     *             if salt is null.
45     */
46    public PBEParameterSpec(byte[] salt, int iterationCount) {
47        if (salt == null) {
48            throw new NullPointerException("salt == null");
49        }
50        this.salt = new byte[salt.length];
51        System.arraycopy(salt, 0, this.salt, 0, salt.length);
52        this.iterationCount = iterationCount;
53    }
54
55    /**
56     * Returns a copy to the salt.
57     *
58     * @return a copy to the salt.
59     */
60    public byte[] getSalt() {
61        byte[] result = new byte[salt.length];
62        System.arraycopy(salt, 0, result, 0, salt.length);
63        return result;
64    }
65
66    /**
67     * Returns the iteration count.
68     *
69     * @return the iteration count.
70     */
71    public int getIterationCount() {
72        return iterationCount;
73    }
74}
75