📄 desedekeyfactory.java
字号:
package au.net.aba.crypto.provider;
/*
* $Id: DESedeKeyFactory.java,v 1.12 1999/02/18 06:28:49 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/DESedeKeyFactory.java,v $
* $Revision: 1.12 $
* $Date: 1999/02/18 06:28:49 $
* $State: Exp $
*/
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
import java.security.InvalidKeyException;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactorySpi;
import javax.crypto.spec.DESedeKeySpec;
import javax.crypto.spec.SecretKeySpec;
/**
* This class is used to convert DESede keys into a format usable by the
* ABA provider. The supported KeySpec classes are DESedeKeySpec and
* SecretKeySpec. In the case of the SecretKeySpec the keydata must be
* at least 24 bytes long and there must be no encoding on the key data.
* The supported Key class is DESKey.
* <p>
* This class should not be instantiated directly, instead use the
* java.security.KeyFactory interface.
*
* @see java.security.KeyFactory
*/
public class DESedeKeyFactory extends SecretKeyFactorySpi
{
public final static String ident = "$Id: DESedeKeyFactory.java,v 1.12 1999/02/18 06:28:49 leachbj Exp $";
/**
* Generates a DESede SecretKey object from the provided key
* specification (key material). This class supports the
* DESedeKeySpec and SecretKeySpec KeySpec classes.
*
* @returns The secret key.
* @exception InvalidKeySpecException The provided KeySpec was not
* a DESKeySpec or SecretKeySpec KeySpec.
*/
protected SecretKey engineGenerateSecret(
KeySpec keySpec)
throws InvalidKeySpecException
{
if (keySpec instanceof DESedeKeySpec)
{
DESedeKeySpec edeKspec = (DESedeKeySpec)keySpec;
return new DESedeKey(edeKspec.getKey());
}
else if (keySpec instanceof SecretKeySpec)
{
SecretKeySpec skspec = (SecretKeySpec)keySpec;
if (!"DESede".equals(skspec.getAlgorithm()))
{
throw new InvalidKeySpecException(
"SecretKeySpec not for DESede");
}
if (!"RAW".equals(skspec.getFormat()))
{
throw new InvalidKeySpecException(
"Unknown format in KeySpec");
}
return new DESedeKey(skspec.getEncoded());
}
throw new InvalidKeySpecException("Invalid KeySpec");
}
/**
* Returns a specification (key material) of the given key object in
* the requested format.
* <p>
* Can convert from ABA's DESede keys into either a SecretKeySpec
* or DESedeKeySpec instance.
*
* @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(
SecretKey key,
Class keySpec)
throws InvalidKeySpecException
{
if (key instanceof DESedeKey)
{
if (SecretKeySpec.class.isAssignableFrom(keySpec))
{
return new SecretKeySpec(key.getEncoded(),
"DESede");
}
else if (DESedeKeySpec.class.isAssignableFrom(keySpec))
{
try
{
return new DESedeKeySpec(
key.getEncoded());
}
catch (InvalidKeyException e)
{
throw new InvalidKeySpecException(
e.getMessage());
}
}
}
throw new InvalidKeySpecException("not implemented");
}
/**
* Translates a DESede 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 SecretKey engineTranslateKey(
SecretKey key)
throws InvalidKeyException
{
if (!key.getAlgorithm().equals("DESede"))
{
throw new InvalidKeyException("not a DESede key");
}
return new DESedeKey(key.getEncoded());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -