![JAR search and dependency download from the Maven repository](/logo.png)
org.bouncycastle.crypto.general.DesKeyGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bc-fips-debug Show documentation
Show all versions of bc-fips-debug Show documentation
The FIPS 140-2 Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms certified to FIPS 140-2 level 1. This jar contains the debug version JCE provider and low-level API for the BC-FJA version 1.0.2.3, FIPS Certificate #3514. Please note the debug jar is not certified.
package org.bouncycastle.crypto.general;
import org.bouncycastle.crypto.internal.KeyGenerationParameters;
import org.bouncycastle.crypto.internal.params.DesParameters;
class DesKeyGenerator
extends CipherKeyGenerator
{
/**
* 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.");
}
}
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;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy