src/java.base/share/classes/javax/crypto/spec/PBEKeySpec.java
author coffeys
Fri, 03 Aug 2018 14:14:59 +0100
changeset 51293 53c3b460503c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8208583: Better management of internal KeyStore buffers Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
51293
53c3b460503c 8208583: Better management of internal KeyStore buffers
coffeys
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.crypto.spec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.security.spec.KeySpec;
51293
53c3b460503c 8208583: Better management of internal KeyStore buffers
coffeys
parents: 47216
diff changeset
    29
import java.util.Arrays;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * A user-chosen password that can be used with password-based encryption
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * (<i>PBE</i>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p>The password can be viewed as some kind of raw key material, from which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * the encryption mechanism that uses it derives a cryptographic key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>Different PBE mechanisms may consume different bits of each password
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * character. For example, the PBE mechanism defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <a href="http://www.ietf.org/rfc/rfc2898.txt">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * PKCS #5</a> looks at only the low order 8 bits of each character, whereas
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * PKCS #12 looks at all 16 bits of each character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>You convert the password characters to a PBE key by creating an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * instance of the appropriate secret-key factory. For example, a secret-key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * factory for PKCS #5 will construct a PBE key from only the low order 8 bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * of each password character, whereas a secret-key factory for PKCS #12 will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * take all 16 bits of each character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>Also note that this class stores passwords as char arrays instead of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <code>String</code> objects (which would seem more logical), because the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * String class is immutable and there is no way to overwrite its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * internal value when the password stored in it is no longer needed. Hence,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * this class requests the password as a char array, so it can be overwritten
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * when done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @author Jan Luehe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author Valerie Peng
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @see javax.crypto.SecretKeyFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @see PBEParameterSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
public class PBEKeySpec implements KeySpec {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private char[] password;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private byte[] salt = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private int iterationCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private int keyLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Constructor that takes a password. An empty char[] is used if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * null is specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * <p> Note: <code>password</code> is cloned before it is stored in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * the new <code>PBEKeySpec</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param password the password.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public PBEKeySpec(char[] password) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        if ((password == null) || (password.length == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            this.password = new char[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        } else {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
    84
            this.password = password.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Constructor that takes a password, salt, iteration count, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * to-be-derived key length for generating PBEKey of variable-key-size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * PBE ciphers.  An empty char[] is used if null is specified for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * <code>password</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * <p> Note: the <code>password</code> and <code>salt</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * are cloned before they are stored in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * the new <code>PBEKeySpec</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param password the password.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @param salt the salt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param iterationCount the iteration count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param keyLength the to-be-derived key length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @exception NullPointerException if <code>salt</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @exception IllegalArgumentException if <code>salt</code> is empty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * i.e. 0-length, <code>iterationCount</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * <code>keyLength</code> is not positive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public PBEKeySpec(char[] password, byte[] salt, int iterationCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        int keyLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if ((password == null) || (password.length == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            this.password = new char[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        } else {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   113
            this.password = password.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (salt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            throw new NullPointerException("the salt parameter " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                            "must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        } else if (salt.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            throw new IllegalArgumentException("the salt parameter " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                                                "must not be empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        } else {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   122
            this.salt = salt.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (iterationCount<=0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            throw new IllegalArgumentException("invalid iterationCount value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (keyLength<=0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            throw new IllegalArgumentException("invalid keyLength value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        this.iterationCount = iterationCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        this.keyLength = keyLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Constructor that takes a password, salt, iteration count for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * generating PBEKey of fixed-key-size PBE ciphers. An empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * char[] is used if null is specified for <code>password</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * <p> Note: the <code>password</code> and <code>salt</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * are cloned before they are stored in the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * <code>PBEKeySpec</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @param password the password.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @param salt the salt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param iterationCount the iteration count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @exception NullPointerException if <code>salt</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @exception IllegalArgumentException if <code>salt</code> is empty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * i.e. 0-length, or <code>iterationCount</code> is not positive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public PBEKeySpec(char[] password, byte[] salt, int iterationCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if ((password == null) || (password.length == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            this.password = new char[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        } else {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   155
            this.password = password.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if (salt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            throw new NullPointerException("the salt parameter " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                                            "must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        } else if (salt.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            throw new IllegalArgumentException("the salt parameter " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                                "must not be empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        } else {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   164
            this.salt = salt.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        if (iterationCount<=0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            throw new IllegalArgumentException("invalid iterationCount value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        this.iterationCount = iterationCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Clears the internal copy of the password.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public final void clearPassword() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (password != null) {
51293
53c3b460503c 8208583: Better management of internal KeyStore buffers
coffeys
parents: 47216
diff changeset
   178
            Arrays.fill(password, ' ');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            password = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * Returns a copy of the password.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * <p> Note: this method returns a copy of the password. It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * the caller's responsibility to zero out the password information after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * it is no longer needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @exception IllegalStateException if password has been cleared by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * calling <code>clearPassword</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @return the password.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public final char[] getPassword() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (password == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            throw new IllegalStateException("password has been cleared");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   198
        return password.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Returns a copy of the salt or null if not specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * <p> Note: this method should return a copy of the salt. It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * the caller's responsibility to zero out the salt information after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * it is no longer needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @return the salt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public final byte[] getSalt() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (salt != null) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   212
            return salt.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Returns the iteration count or 0 if not specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @return the iteration count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public final int getIterationCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return iterationCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Returns the to-be-derived key length or 0 if not specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * <p> Note: this is used to indicate the preference on key length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * for variable-key-size ciphers. The actual key size depends on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * each provider's implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @return the to-be-derived key length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public final int getKeyLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return keyLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
}