📄 blowfishkeygenerator.java
字号:
package au.net.aba.crypto.provider;
/*
* $Id: BlowfishKeyGenerator.java,v 1.5 1998/10/27 05:10:54 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/BlowfishKeyGenerator.java,v $
* $Revision: 1.5 $
* $Date: 1998/10/27 05:10:54 $
* $State: Exp $
*/
import java.security.InvalidAlgorithmParameterException;
import java.security.spec.AlgorithmParameterSpec;
import java.security.SecureRandom;
import javax.crypto.KeyGeneratorSpi;
import javax.crypto.SecretKey;
/**
* This class is used for generating random Blowfish keys. This class
* should not be instantiated directly, instead use the
* javax.crypto.KeyGenerator interface.
* <p>
* There is no AlgorithmParameterSpec class defined for Blowfish so this
* generator can only be initialised using the keysize,random
* initialisation.
* <p>
* The default keysize is 192 bits and can be any multiple of 8 up to
* 448 bits.
*/
public class BlowfishKeyGenerator extends KeyGeneratorSpi
{
public final static String ident = "$Id: BlowfishKeyGenerator.java,v 1.5 1998/10/27 05:10:54 leachbj Exp $";
static final int DEF_KEY_SIZE = 192; /* standard key size in bits */
private SecureRandom rand;
private int strength = DEF_KEY_SIZE;
/**
* Generates a random secret key of the currently configured
* keysize and using the configured random source.
*
* @return a secret key representing a Blowfish key.
*/
protected SecretKey engineGenerateKey()
{
byte[] bytes;
bytes = new byte[(strength + 7) / 8];
if (rand == null)
{
rand = new SecureRandom();
}
rand.nextBytes(bytes);
return new BlowfishKey(bytes);
}
/**
* Initialises this key generator for a certain strength, using the
* given source of randomness.
*
* @param strength the strength of the key. This is an
* algorithm-specific metric specified in number of bits.
* @param random the source of randomness for this key generator
*/
protected void engineInit(
int strength,
SecureRandom random)
{
this.strength = strength;
this.rand = random;
}
/**
* Initialises the key generator with the given random number source.
*
* @param random a source of random numbers for this generator.
*/
protected void engineInit(
SecureRandom random)
{
rand = random;
}
/**
* This method is not implemented as there is no AlgorithmParameterSpec
* defined for Blowfish. (Use one of the other initialisation methods!)
*
* @param params The algorithm parameter specs for this
* generator.
* @param random A source of random numbers for this generator.
* @exception InvalidAlgorithmParameterException An invalid
* parameter specification is provided.
*/
protected void engineInit(
AlgorithmParameterSpec params,
SecureRandom random)
throws InvalidAlgorithmParameterException
{
throw new InvalidAlgorithmParameterException("Not Implemented");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -