📄 dhkeyfactory.java
字号:
package au.net.aba.crypto.provider;
/*
* $Id: DHKeyFactory.java,v 1.8 1999/02/17 01:43:05 leachbj Exp $
* $Author: leachbj $
*
* Copyright (C) 1996-1998 Australian Business Access Pty Ltd.
* All rights reserved.
*
* Use, modification, copying and distribution of this software is subject the
* terms and conditions of the ABA Public Licence. See the file
* "PUBLIC_LICENCE" for additional information.
*
* If you have not received a copy of the Public Licence, you must destroy all
* copies of this file immediately.
*
* $Source: /aba/CVSROOT/jdk1.1/src/au.net.aba/crypto/provider/DHKeyFactory.java,v $
* $Revision: 1.8 $
* $Date: 1999/02/17 01:43:05 $
* $State: Exp $
*/
import java.security.*;
import javax.crypto.interfaces.*;
import javax.crypto.spec.*;
import java.security.*;
import java.security.spec.*;
/**
* This class is used to convert Diffie-Hellman keys into a format
* usable by the ABA provider. Currently this class can only convert
* from a KeySpec into a Key. The supported KeySpec classes are
* DHPublicKeySpec and DHPrivateKeySpec.
* <p>
* Not currently finished.
* <p>
* This class should not be instantiated directly, instead use the
* java.security.KeyFactory interface.
*
* @see java.security.KeyFactory
*/
public class DHKeyFactory extends KeyFactorySpi
{
public final static String ident = "$Id: DHKeyFactory.java,v 1.8 1999/02/17 01:43:05 leachbj Exp $";
/**
* Generates a Diffie-Hellman PrivateKey object from the provided key
* specification (key material). This class supports the
* DHPrivateKeySpec KeySpec class.
*
* @returns The private key.
* @exception InvalidKeySpecException The provided KeySpec was not
* a DHPrivateKeySpec KeySpec.
*/
protected PrivateKey engineGeneratePrivate(
KeySpec keySpec)
throws InvalidKeySpecException
{
if (keySpec instanceof DHPrivateKeySpec)
{
DHPrivateKeySpec privKeySpec;
privKeySpec = (DHPrivateKeySpec)keySpec;
return new DHPrivKey(privKeySpec.getX(),
privKeySpec.getP(), privKeySpec.getG());
}
throw new InvalidKeySpecException(
"Bad key specification");
}
/**
* Generates a Diffie-Hellman PublicKey object from the provided key
* specification (key material). This class supports the
* DHPublicKeySpec KeySpec class.
*
* @returns The private key.
* @exception InvalidKeySpecException The provided KeySpec was not
* a DHPublicKeySpec KeySpec.
*/
protected PublicKey engineGeneratePublic(
KeySpec keySpec)
throws InvalidKeySpecException
{
if (keySpec instanceof DHPublicKeySpec)
{
DHPublicKeySpec pubKeySpec;
pubKeySpec = (DHPublicKeySpec)keySpec;
return new DHPubKey(pubKeySpec.getY(),
pubKeySpec.getP(), pubKeySpec.getG());
}
throw new InvalidKeySpecException(
"Bad key specification");
}
/**
* Returns a specification (key material) of the given key object in
* the requested format.
* <p>
* Currently supports standard DH keys, DHPublicKeySpec and
* DHPrivateKeySpec KeySpec classes.
*
* @param key the key
* @param keySpec the requested format in which the key material shall
* be returned
* @returns the underlying key specification (key material) in the
* requested format
* @exception InvalidKeySpecException if the requested key
* specification is inappropriate for the given key, or the given
* key cannot be dealt with (e.g., the given key has an
* unrecognised format).
*/
protected KeySpec engineGetKeySpec(
Key key,
Class spec)
throws InvalidKeySpecException
{
if (key instanceof DHPublicKey)
{
if (DHPublicKeySpec.class.isAssignableFrom(spec))
{
DHPublicKey dh;
DHParameterSpec params;
dh = (DHPublicKey)key;
params = dh.getParams();
return new DHPublicKeySpec(dh.getY(),
params.getP(), params.getG());
}
}
else if (key instanceof DHPrivateKey)
{
if (DHPrivateKeySpec.class.isAssignableFrom(spec))
{
DHPrivateKey dh;
DHParameterSpec params;
dh = (DHPrivateKey)key;
params = dh.getParams();
return new DHPrivateKeySpec(dh.getX(),
params.getP(), params.getG());
}
}
throw new InvalidKeySpecException("Invalid Key or KeySpec.");
}
/**
* Translates a Diffie-Hellman key object, whose provider may be
* unknown or potentially untrusted, into a corresponding key
* object of this key factory.
*
* @param key - the key whose provider is unknown or untrusted
* @returns the translated key
* @exception InvalidKeyException if the given key cannot be processed
* by this key factory.
*/
protected Key engineTranslateKey(
Key key)
throws InvalidKeyException
{
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -