?? rc4keygenerator.java
字號:
package au.net.aba.crypto.provider;
/*
* $Id: RC4KeyGenerator.java,v 1.11 1998/10/27 05:11:02 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/RC4KeyGenerator.java,v $
* $Revision: 1.11 $
* $Date: 1998/10/27 05:11:02 $
* $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 RC4 keys. This class
* should not be instantiated directly, instead use the
* javax.crypto.KeyGenerator interface.
* <p>
* There is no AlgorithmParameterSpec class defined for RC4 so this
* generator can only be initialised using the keysize,random
* initialisation.
* <p>
* The default keysize is 128 bits, and may be any multiple of 8 less
* than (or equal to) 256.
*/
public class RC4KeyGenerator extends KeyGeneratorSpi
{
public final static String ident = "$Id: RC4KeyGenerator.java,v 1.11 1998/10/27 05:11:02 leachbj Exp $";
static final int DEF_KEY_SIZE = 128; /* standard key size */
private int strength = DEF_KEY_SIZE;
private SecureRandom random;
/**
* Generates a random secret key.
*
* @return the RC4 key.
*/
protected SecretKey engineGenerateKey()
{
byte[] bytes;
bytes = new byte[(strength + 7) / 8];
/*
* In case engineInit() was not called
*/
if (random == null)
{
random = new SecureRandom();
}
random.nextBytes(bytes);
return new RC4Key(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.random = random;
}
/**
* Initialises the key generator with the given random source.
*
* @param random a source of random numbers for this generator.
*/
protected void engineInit(
SecureRandom random)
{
this.random = random;
}
/**
* This method is not implemented as there is no AlgorithmParameterSpec
* defined for RC4. (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 + -