jdk/src/share/classes/com/sun/crypto/provider/DHKeyFactory.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 3353 ddbd63234844
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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 com.sun.crypto.provider;
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
import java.lang.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.Key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.PublicKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.PrivateKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.KeyFactorySpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.InvalidKeyException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.spec.KeySpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.spec.InvalidKeySpecException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.security.spec.X509EncodedKeySpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.spec.PKCS8EncodedKeySpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.crypto.spec.DHPublicKeySpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.crypto.spec.DHPrivateKeySpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.crypto.spec.DHParameterSpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * This class implements the Diffie-Hellman key factory of the Sun provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author Jan Luehe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public final class DHKeyFactory extends KeyFactorySpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * Verify the SunJCE provider in the constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * @exception SecurityException if fails to verify
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * its own integrity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public DHKeyFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        if (!SunJCE.verifySelfIntegrity(this.getClass())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            throw new SecurityException("The SunJCE provider may have " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                                        "been tampered.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Generates a public key object from the provided key specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * (key material).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @param keySpec the specification (key material) of the public key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @return the public key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @exception InvalidKeySpecException if the given key specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * is inappropriate for this key factory to produce a public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    protected PublicKey engineGeneratePublic(KeySpec keySpec)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        throws InvalidKeySpecException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            if (keySpec instanceof DHPublicKeySpec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                DHPublicKeySpec dhPubKeySpec = (DHPublicKeySpec)keySpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                return new DHPublicKey(dhPubKeySpec.getY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                       dhPubKeySpec.getP(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                       dhPubKeySpec.getG());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            } else if (keySpec instanceof X509EncodedKeySpec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                return new DHPublicKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                    (((X509EncodedKeySpec)keySpec).getEncoded());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                throw new InvalidKeySpecException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                    ("Inappropriate key specification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        } catch (InvalidKeyException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            throw new InvalidKeySpecException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                ("Inappropriate key specification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Generates a private key object from the provided key specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * (key material).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param keySpec the specification (key material) of the private key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @return the private key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @exception InvalidKeySpecException if the given key specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * is inappropriate for this key factory to produce a private key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        throws InvalidKeySpecException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            if (keySpec instanceof DHPrivateKeySpec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                DHPrivateKeySpec dhPrivKeySpec = (DHPrivateKeySpec)keySpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                return new DHPrivateKey(dhPrivKeySpec.getX(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                        dhPrivKeySpec.getP(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                        dhPrivKeySpec.getG());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            } else if (keySpec instanceof PKCS8EncodedKeySpec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                return new DHPrivateKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    (((PKCS8EncodedKeySpec)keySpec).getEncoded());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                throw new InvalidKeySpecException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    ("Inappropriate key specification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        } catch (InvalidKeyException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            throw new InvalidKeySpecException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                ("Inappropriate key specification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
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
     * Returns a specification (key material) of the given key object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * in the requested format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param key the key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @param keySpec the requested format in which the key material shall be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @return the underlying key specification (key material) in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * requested format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @exception InvalidKeySpecException if the requested key specification is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * inappropriate for the given key, or the given key cannot be processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * (e.g., the given key has an unrecognized algorithm or format).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    protected KeySpec engineGetKeySpec(Key key, Class keySpec)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        throws InvalidKeySpecException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        DHParameterSpec params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if (key instanceof javax.crypto.interfaces.DHPublicKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            if (DHPublicKeySpec.class.isAssignableFrom(keySpec)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                javax.crypto.interfaces.DHPublicKey dhPubKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    = (javax.crypto.interfaces.DHPublicKey) key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                params = dhPubKey.getParams();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                return new DHPublicKeySpec(dhPubKey.getY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                           params.getP(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                           params.getG());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            } else if (X509EncodedKeySpec.class.isAssignableFrom(keySpec)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                return new X509EncodedKeySpec(key.getEncoded());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                throw new InvalidKeySpecException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    ("Inappropriate key specification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        } else if (key instanceof javax.crypto.interfaces.DHPrivateKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            if (DHPrivateKeySpec.class.isAssignableFrom(keySpec)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                javax.crypto.interfaces.DHPrivateKey dhPrivKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    = (javax.crypto.interfaces.DHPrivateKey)key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                params = dhPrivKey.getParams();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                return new DHPrivateKeySpec(dhPrivKey.getX(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                            params.getP(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                                            params.getG());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            } else if (PKCS8EncodedKeySpec.class.isAssignableFrom(keySpec)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                return new PKCS8EncodedKeySpec(key.getEncoded());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                throw new InvalidKeySpecException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    ("Inappropriate key specification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            throw new InvalidKeySpecException("Inappropriate key type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Translates a key object, whose provider may be unknown or potentially
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * untrusted, into a corresponding key object of this key factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param key the key whose provider is unknown or untrusted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @return the translated key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @exception InvalidKeyException if the given key cannot be processed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * this key factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    protected Key engineTranslateKey(Key key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        throws InvalidKeyException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            if (key instanceof javax.crypto.interfaces.DHPublicKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                // Check if key originates from this factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                if (key instanceof com.sun.crypto.provider.DHPublicKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    return key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                // Convert key to spec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                DHPublicKeySpec dhPubKeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    = (DHPublicKeySpec)engineGetKeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    (key, DHPublicKeySpec.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                // Create key from spec, and return it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                return engineGeneratePublic(dhPubKeySpec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            } else if (key instanceof javax.crypto.interfaces.DHPrivateKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                // Check if key originates from this factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                if (key instanceof com.sun.crypto.provider.DHPrivateKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    return key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                // Convert key to spec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                DHPrivateKeySpec dhPrivKeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    = (DHPrivateKeySpec)engineGetKeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    (key, DHPrivateKeySpec.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                // Create key from spec, and return it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                return engineGeneratePrivate(dhPrivKeySpec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                throw new InvalidKeyException("Wrong algorithm type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        } catch (InvalidKeySpecException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            throw new InvalidKeyException("Cannot translate key");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
}