Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / javax / crypto / spec / PBEKeySpec.java
blobd17dc41eef7b3b24f3cdfb749d7f404732eebcba
1 /* PBEKeySpec.java -- Wrapper for password-based keys.
2 Copyright (C) 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.crypto.spec;
41 import java.security.spec.KeySpec;
43 /**
44 * A wrapper for a password-based key, used for password-based
45 * encryption (PBE).
47 * <p>Examples of password-based encryption algorithms include:
49 * <ul>
50 * <li><a href="http://www.rsasecurity.com/rsalabs/pkcs/pkcs-5/">PKCS #5
51 * - Password-Based Cryptography Standard</a></li>
52 * <li><a href="http://www.rsasecurity.com/rsalabs/pkcs/pkcs-12/">PKCS
53 * #12 - Personal Information Exchange Syntax Standard</a></li>
54 * </ul>
56 * @author Casey Marshall (csm@gnu.org)
57 * @since 1.4
58 * @see javax.crypto.SecretKeyFactory
59 * @see PBEParameterSpec
61 public class PBEKeySpec implements KeySpec
64 // Fields.
65 // ------------------------------------------------------------------------
67 /** The iteration count. */
68 private int iterationCount;
70 /** The generated key length. */
71 private int keyLength;
73 /** The password. */
74 private char[] password;
76 /** The salt. */
77 private byte[] salt;
79 // Constructors.
80 // ------------------------------------------------------------------------
82 /**
83 * Create a new PBE key spec with just a password.
85 * @param password The password char array.
87 public PBEKeySpec(char[] password)
89 this(password, null, 0, 0);
92 /**
93 * Create a PBE key spec with a password, salt, and iteration count.
95 * @param password The password char array.
96 * @param salt The salt bytes.
97 * @param iterationCount The iteration count.
99 public PBEKeySpec(char[] password, byte[] salt, int iterationCount)
101 this(password, salt, iterationCount, 0);
105 * Create a PBE key spec with a password, salt, iteration count, and
106 * key length.
108 * @param password The password char array.
109 * @param salt The salt bytes.
110 * @param iterationCount The iteration count.
111 * @param keyLength The generated key length.
113 public PBEKeySpec(char[] password, byte[] salt, int iterationCount,
114 int keyLength)
116 this.password = password;
117 this.salt = salt;
118 this.iterationCount = iterationCount;
119 this.keyLength = keyLength;
122 // Instance methods.
123 // ------------------------------------------------------------------------
126 * Clear the password array by filling it with null characters.
128 public final void clearPassword()
130 if (password == null) return;
131 for (int i = 0; i < password.length; i++)
133 password[i] = '\u0000';
138 * Get the iteration count, or 0 if it has not been specified.
140 * @return The iteration count, or 0 if it has not been specified.
142 public final int getIterationCount()
144 return iterationCount;
148 * Get the generated key length, or 0 if it has not been specified.
150 * @return The key length, or 0 if it has not been specified.
152 public final int getKeyLength()
154 return keyLength;
158 * Get the password character array.
160 * @return The password.
162 public final char[] getPassword()
164 return password;
168 * Get the salt bytes.
170 * @return The salt.
172 public final byte[] getSalt()
174 return salt;