jdk/src/java.base/share/classes/javax/crypto/SecretKeyFactory.java
author ascarpino
Mon, 19 Oct 2015 17:35:18 -0700
changeset 33241 27eb2d6abda9
parent 32275 17eeb583a331
child 37348 9ccec3170d5e
permissions -rw-r--r--
8133151: Preferred provider configuration for JCE Reviewed-by: valeriep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32275
diff changeset
     2
 * Copyright (c) 1997, 2015, 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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.Provider.Service;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.spec.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.security.jca.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.security.jca.GetInstance.Instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * This class represents a factory for secret keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <P> Key factories are used to convert <I>keys</I> (opaque
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
    41
 * cryptographic keys of type {@code Key}) into <I>key specifications</I>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * (transparent representations of the underlying key material), and vice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Secret key factories operate only on secret (symmetric) keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <P> Key factories are bi-directional, i.e., they allow to build an opaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * key object from a given key specification (key material), or to retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * the underlying key material of a key object in a suitable format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <P> Application developers should refer to their provider's documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * to find out which key specifications are supported by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * {@link #generateSecret(java.security.spec.KeySpec) generateSecret} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * {@link #getKeySpec(javax.crypto.SecretKey, java.lang.Class) getKeySpec}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * For example, the DES secret-key factory supplied by the "SunJCE" provider
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
    56
 * supports {@code DESKeySpec} as a transparent representation of DES
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * keys, and that provider's secret-key factory for Triple DES keys supports
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
    58
 * {@code DESedeKeySpec} as a transparent representation of Triple DES
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    61
 * <p> Every implementation of the Java platform is required to support the
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
    62
 * following standard {@code SecretKeyFactory} algorithms:
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    63
 * <ul>
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
    64
 * <li>{@code DES}</li>
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
    65
 * <li>{@code DESede}</li>
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    66
 * </ul>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    67
 * These algorithms are described in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    68
 * "{@docRoot}/../technotes/guides/security/StandardNames.html#SecretKeyFactory">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    69
 * SecretKeyFactory section</a> of the
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    70
 * Java Cryptography Architecture Standard Algorithm Name Documentation.
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    71
 * Consult the release documentation for your implementation to see if any
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    72
 * other algorithms are supported.
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    73
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @author Jan Luehe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * @see SecretKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * @see javax.crypto.spec.DESKeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * @see javax.crypto.spec.DESedeKeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @see javax.crypto.spec.PBEKeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
public class SecretKeyFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    // The provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private Provider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    // The algorithm associated with this factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private final String algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    // The provider implementation (delegate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private volatile SecretKeyFactorySpi spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // lock for mutex during provider selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private final Object lock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    // remaining services to try in provider selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    // null once provider is selected
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 8575
diff changeset
    99
    private Iterator<Service> serviceIterator;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Creates a SecretKeyFactory object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param keyFacSpi the delegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @param provider the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param algorithm the secret-key algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    protected SecretKeyFactory(SecretKeyFactorySpi keyFacSpi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                               Provider provider, String algorithm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        this.spi = keyFacSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        this.algorithm = algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private SecretKeyFactory(String algorithm) throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        this.algorithm = algorithm;
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 8575
diff changeset
   117
        List<Service> list =
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 8575
diff changeset
   118
                GetInstance.getServices("SecretKeyFactory", algorithm);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        serviceIterator = list.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        // fetch and instantiate initial spi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (nextSpi(null) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            throw new NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                (algorithm + " SecretKeyFactory not available");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
   128
     * Returns a {@code SecretKeyFactory} object that converts
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * secret keys of the specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * <p> This method traverses the list of registered security Providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * A new SecretKeyFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * SecretKeyFactorySpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Provider that supports the specified algorithm is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32275
diff changeset
   140
     * @implNote
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32275
diff changeset
   141
     * The JDK Reference Implementation additionally uses the
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32275
diff changeset
   142
     * {@code jdk.security.provider.preferred} property to determine
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32275
diff changeset
   143
     * the preferred provider order for the specified algorithm. This
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32275
diff changeset
   144
     * may be different than the order of providers returned by
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32275
diff changeset
   145
     * {@link Security#getProviders() Security.getProviders()}.
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32275
diff changeset
   146
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @param algorithm the standard name of the requested secret-key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * algorithm.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   149
     * See the SecretKeyFactory section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   150
     * "{@docRoot}/../technotes/guides/security/StandardNames.html#SecretKeyFactory">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   151
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
   154
     * @return the new {@code SecretKeyFactory} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @exception NullPointerException if the specified algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *          is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @exception NoSuchAlgorithmException if no Provider supports a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *          SecretKeyFactorySpi implementation for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *          specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public static final SecretKeyFactory getInstance(String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return new SecretKeyFactory(algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
   171
     * Returns a {@code SecretKeyFactory} object that converts
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * secret keys of the specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * <p> A new SecretKeyFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * SecretKeyFactorySpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * is returned.  The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @param algorithm the standard name of the requested secret-key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * algorithm.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   184
     * See the SecretKeyFactory section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   185
     * "{@docRoot}/../technotes/guides/security/StandardNames.html#SecretKeyFactory">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   186
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @param provider the name of the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
   191
     * @return the new {@code SecretKeyFactory} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @exception NoSuchAlgorithmException if a SecretKeyFactorySpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *          implementation for the specified algorithm is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *          available from the specified provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @exception NullPointerException if the specified algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *          is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @throws NoSuchProviderException if the specified provider is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *          registered in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
   203
     * @exception IllegalArgumentException if the {@code provider}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *          is null or empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public static final SecretKeyFactory getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            String provider) throws NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            NoSuchProviderException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        Instance instance = JceSecurity.getInstance("SecretKeyFactory",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                SecretKeyFactorySpi.class, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return new SecretKeyFactory((SecretKeyFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
   218
     * Returns a {@code SecretKeyFactory} object that converts
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * secret keys of the specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * <p> A new SecretKeyFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * SecretKeyFactorySpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param algorithm the standard name of the requested secret-key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * algorithm.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   228
     * See the SecretKeyFactory section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   229
     * "{@docRoot}/../technotes/guides/security/StandardNames.html#SecretKeyFactory">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   230
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @param provider the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
   235
     * @return the new {@code SecretKeyFactory} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @exception NullPointerException if the specified algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @exception NoSuchAlgorithmException if a SecretKeyFactorySpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *          implementation for the specified algorithm is not available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *          from the specified Provider object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
   244
     * @exception IllegalArgumentException if the {@code provider}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *          is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public static final SecretKeyFactory getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            Provider provider) throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        Instance instance = JceSecurity.getInstance("SecretKeyFactory",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                SecretKeyFactorySpi.class, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return new SecretKeyFactory((SecretKeyFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
   258
     * Returns the provider of this {@code SecretKeyFactory} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
   260
     * @return the provider of this {@code SecretKeyFactory} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            // disable further failover after this call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            serviceIterator = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            return provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
   271
     * Returns the algorithm name of this {@code SecretKeyFactory} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * <p>This is the same name that was specified in one of the
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
   274
     * {@code getInstance} calls that created this
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
   275
     * {@code SecretKeyFactory} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
   277
     * @return the algorithm name of this {@code SecretKeyFactory}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public final String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return this.algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * Update the active spi of this class and return the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * implementation for failover. If no more implemenations are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * available, this method returns null. However, the active spi of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * this class is never set to null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    private SecretKeyFactorySpi nextSpi(SecretKeyFactorySpi oldSpi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            // somebody else did a failover concurrently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            // try that spi now
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            if ((oldSpi != null) && (oldSpi != spi)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                return spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            if (serviceIterator == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            while (serviceIterator.hasNext()) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 8575
diff changeset
   301
                Service s = serviceIterator.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                if (JceSecurity.canUseProvider(s.getProvider()) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    Object obj = s.newInstance(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    if (obj instanceof SecretKeyFactorySpi == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    SecretKeyFactorySpi spi = (SecretKeyFactorySpi)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    provider = s.getProvider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    this.spi = spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                    return spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                } catch (NoSuchAlgorithmException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            serviceIterator = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
   324
     * Generates a {@code SecretKey} object from the provided key
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * specification (key material).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @param keySpec the specification (key material) of the secret key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @return the secret key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @exception InvalidKeySpecException if the given key specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * is inappropriate for this secret-key factory to produce a secret key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    public final SecretKey generateSecret(KeySpec keySpec)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            throws InvalidKeySpecException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        if (serviceIterator == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            return spi.engineGenerateSecret(keySpec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        Exception failure = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        SecretKeyFactorySpi mySpi = spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                return mySpi.engineGenerateSecret(keySpec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                if (failure == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                    failure = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                mySpi = nextSpi(mySpi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        } while (mySpi != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        if (failure instanceof InvalidKeySpecException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            throw (InvalidKeySpecException)failure;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        throw new InvalidKeySpecException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                ("Could not generate secret key", failure);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * Returns a specification (key material) of the given key object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * in the requested format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @param key the key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @param keySpec the requested format in which the key material shall be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @return the underlying key specification (key material) in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * requested format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @exception InvalidKeySpecException if the requested key specification is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * inappropriate for the given key (e.g., the algorithms associated with
32275
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
   371
     * {@code key} and {@code keySpec} do not match, or
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
   372
     * {@code key} references a key on a cryptographic hardware device
17eeb583a331 8133802: replace some <tt> tags (obsolete in html5) in security-libs docs
avstepan
parents: 25859
diff changeset
   373
     * whereas {@code keySpec} is the specification of a software-based
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * key), or the given key cannot be dealt with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * (e.g., the given key has an algorithm or format not supported by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * secret-key factory).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 8575
diff changeset
   378
    public final KeySpec getKeySpec(SecretKey key, Class<?> keySpec)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            throws InvalidKeySpecException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        if (serviceIterator == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            return spi.engineGetKeySpec(key, keySpec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        Exception failure = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        SecretKeyFactorySpi mySpi = spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                return mySpi.engineGetKeySpec(key, keySpec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                if (failure == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                    failure = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                mySpi = nextSpi(mySpi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        } while (mySpi != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        if (failure instanceof InvalidKeySpecException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            throw (InvalidKeySpecException)failure;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        throw new InvalidKeySpecException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                ("Could not get key spec", failure);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * Translates a key object, whose provider may be unknown or potentially
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * untrusted, into a corresponding key object of this secret-key factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @param key the key whose provider is unknown or untrusted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @return the translated key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * @exception InvalidKeyException if the given key cannot be processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * by this secret-key factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public final SecretKey translateKey(SecretKey key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            throws InvalidKeyException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        if (serviceIterator == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            return spi.engineTranslateKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        Exception failure = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        SecretKeyFactorySpi mySpi = spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                return mySpi.engineTranslateKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                if (failure == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    failure = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                mySpi = nextSpi(mySpi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        } while (mySpi != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        if (failure instanceof InvalidKeyException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            throw (InvalidKeyException)failure;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        throw new InvalidKeyException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                ("Could not translate key", failure);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
}