📄 blowfishkeyspec.java
字号:
package au.net.aba.crypto.spec;
/*
* $Id: BlowfishKeySpec.java,v 1.3 1998/10/05 05:47:54 dgh Exp $
* $Author: dgh $
*
* 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/spec/BlowfishKeySpec.java,v $
* $Revision: 1.3 $
* $Date: 1998/10/05 05:47:54 $
* $State: Exp $
*/
import java.security.spec.KeySpec;
import java.security.InvalidKeyException;
/**
* A class that provides a specification for a Blowfish key.
*/
public class BlowfishKeySpec implements KeySpec
{
public final static String ident = "$Id: BlowfishKeySpec.java,v 1.3 1998/10/05 05:47:54 dgh Exp $";
private byte[] bfKey;
private static int MAXBFKEY_LENGTH = 56;
private static int MINBFKEY_LENGTH = 16;
/**
* Uses the first 56 bytes (if available) as the key, starting at 0
*
* @param key the byte array to use as key material.
* @exception InvalidKeyException if the key material is too short.
*/
public BlowfishKeySpec(
byte[] key)
throws InvalidKeyException
{
this(key, 0);
}
/**
* Uses the first 56 bytes (if available) in key, beginning at offset,
* as the Blowfish key
*
* @param key the byte array to use as key material.
* @param offset the offset to start at.
* @exception InvalidKeyException if the key material is too short.
*/
public BlowfishKeySpec(
byte[] key,
int offset)
throws InvalidKeyException
{
int a = key.length - offset; // available bytes
if (a < MINBFKEY_LENGTH)
{
throw new InvalidKeyException(
"Key too short (min "
+ MINBFKEY_LENGTH + " bytes)");
}
else if (a > MAXBFKEY_LENGTH)
{
a = MAXBFKEY_LENGTH;
}
bfKey = new byte[a];
System.arraycopy(key, offset, bfKey, 0, a);
}
/**
* Returns the Blowfish key.
*
* @return the bytes making up the key.
*/
public byte[] getKey()
{
return bfKey;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -