本文整理汇总了Java中org.bouncycastle.crypto.params.DESParameters类的典型用法代码示例。如果您正苦于以下问题:Java DESParameters类的具体用法?Java DESParameters怎么用?Java DESParameters使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DESParameters类属于org.bouncycastle.crypto.params包,在下文中一共展示了DESParameters类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.bouncycastle.crypto.params.DESParameters; //导入依赖的package包/类
/**
* initialise the key generator - if strength is set to zero
* the key generated will be 64 bits in size, otherwise
* strength can be 64 or 56 bits (if you don't count the parity bits).
*
* @param param the parameters to be used for key generation
*/
public void init(
KeyGenerationParameters param)
{
super.init(param);
if (strength == 0 || strength == (56 / 8))
{
strength = DESParameters.DES_KEY_LENGTH;
}
else if (strength != DESParameters.DES_KEY_LENGTH)
{
throw new IllegalArgumentException("DES key must be "
+ (DESParameters.DES_KEY_LENGTH * 8)
+ " bits long.");
}
}
示例2: generateKey
import org.bouncycastle.crypto.params.DESParameters; //导入依赖的package包/类
public byte[] generateKey()
{
byte[] newKey = new byte[DESParameters.DES_KEY_LENGTH];
do
{
random.nextBytes(newKey);
DESParameters.setOddParity(newKey);
}
while (DESParameters.isWeakKey(newKey, 0));
return newKey;
}
示例3: engineGenerateSecret
import org.bouncycastle.crypto.params.DESParameters; //导入依赖的package包/类
protected SecretKey engineGenerateSecret(
String algorithm)
{
if (x == null)
{
throw new IllegalStateException("Diffie-Hellman not initialised.");
}
String algKey = Strings.toUpperCase(algorithm);
byte[] res = bigIntToBytes(result);
if (algorithms.containsKey(algKey))
{
Integer length = (Integer)algorithms.get(algKey);
byte[] key = new byte[length.intValue() / 8];
System.arraycopy(res, 0, key, 0, key.length);
if (algKey.startsWith("DES"))
{
DESParameters.setOddParity(key);
}
return new SecretKeySpec(key, algorithm);
}
return new SecretKeySpec(res, algorithm);
}
示例4: performTest
import org.bouncycastle.crypto.params.DESParameters; //导入依赖的package包/类
public void performTest()
{
byte[] k1In = { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff,
(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff };
byte[] k1Out = { (byte)0xfe, (byte)0xfe, (byte)0xfe, (byte)0xfe,
(byte)0xfe, (byte)0xfe, (byte)0xfe, (byte)0xfe };
byte[] k2In = { (byte)0xef, (byte)0xcb, (byte)0xda, (byte)0x4f,
(byte)0xaa, (byte)0x99, (byte)0x7f, (byte)0x63 };
byte[] k2Out = { (byte)0xef, (byte)0xcb, (byte)0xda, (byte)0x4f,
(byte)0xab, (byte)0x98, (byte)0x7f, (byte)0x62 };
DESParameters.setOddParity(k1In);
for (int i = 0; i != k1In.length; i++)
{
if (k1In[i] != k1Out[i])
{
fail("Failed "
+ "got " + new String(Hex.encode(k1In))
+ " expected " + new String(Hex.encode(k1Out)));
}
}
DESParameters.setOddParity(k2In);
for (int i = 0; i != k2In.length; i++)
{
if (k2In[i] != k2Out[i])
{
fail("Failed "
+ "got " + new String(Hex.encode(k2In))
+ " expected " + new String(Hex.encode(k2Out)));
}
}
}
示例5: engineGenerateSecret
import org.bouncycastle.crypto.params.DESParameters; //导入依赖的package包/类
protected SecretKey engineGenerateSecret(
KeySpec keySpec)
throws InvalidKeySpecException
{
if (keySpec instanceof PBEKeySpec)
{
PBEKeySpec pbeSpec = (PBEKeySpec)keySpec;
CipherParameters param;
if (pbeSpec.getSalt() == null)
{
return new BCPBEKey(this.algName, this.algOid, scheme, digest, keySize, ivSize, pbeSpec, null);
}
if (forCipher)
{
param = PBE.Util.makePBEParameters(pbeSpec, scheme, digest, keySize, ivSize);
}
else
{
param = PBE.Util.makePBEMacParameters(pbeSpec, scheme, digest, keySize);
}
KeyParameter kParam;
if (param instanceof ParametersWithIV)
{
kParam = (KeyParameter)((ParametersWithIV)param).getParameters();
}
else
{
kParam = (KeyParameter)param;
}
DESParameters.setOddParity(kParam.getKey());
return new BCPBEKey(this.algName, this.algOid, scheme, digest, keySize, ivSize, pbeSpec, param);
}
throw new InvalidKeySpecException("Invalid KeySpec");
}
示例6: generateKey
import org.bouncycastle.crypto.params.DESParameters; //导入依赖的package包/类
private byte[] generateKey() {
SecureRandom random = new SecureRandom();
random.setSeed(UUID.randomUUID().toString().getBytes());
KeyGenerationParameters generationParameters = new KeyGenerationParameters(random, DESParameters.DES_KEY_LENGTH * 8);
DESKeyGenerator generator = new DESKeyGenerator();
generator.init(generationParameters);
return Hex.encode(generator.generateKey());
}