use of org.gudy.bouncycastle.crypto.params.KeyParameter in project BiglyBT by BiglySoftware.
the class PEMUtilities method getKey.
private static SecretKey getKey(char[] password, String algorithm, int keyLength, byte[] salt, boolean des2) throws IOException {
OpenSSLPBEParametersGenerator pGen = new OpenSSLPBEParametersGenerator();
pGen.init(PBEParametersGenerator.PKCS5PasswordToBytes(password), salt);
KeyParameter keyParam;
keyParam = (KeyParameter) pGen.generateDerivedParameters(keyLength * 8);
byte[] key = keyParam.getKey();
if (des2 && key.length >= 24) {
// For DES2, we must copy first 8 bytes into the last 8 bytes.
System.arraycopy(key, 0, key, 16, 8);
}
return new javax.crypto.spec.SecretKeySpec(key, algorithm);
}
use of org.gudy.bouncycastle.crypto.params.KeyParameter in project BiglyBT by BiglySoftware.
the class PKCS12ParametersGenerator method generateDerivedParameters.
/**
* Generate a key with initialisation vector parameter derived from
* the password, salt, and iteration count we are currently initialised
* with.
*
* @param keySize the size of the key we want (in bits)
* @param ivSize the size of the iv we want (in bits)
* @return a ParametersWithIV object.
*/
@Override
public CipherParameters generateDerivedParameters(int keySize, int ivSize) {
keySize = keySize / 8;
ivSize = ivSize / 8;
byte[] dKey = generateDerivedKey(KEY_MATERIAL, keySize);
byte[] iv = generateDerivedKey(IV_MATERIAL, ivSize);
return new ParametersWithIV(new KeyParameter(dKey, 0, keySize), iv, 0, ivSize);
}
use of org.gudy.bouncycastle.crypto.params.KeyParameter in project BiglyBT by BiglySoftware.
the class OpenSSLPBEParametersGenerator method generateDerivedParameters.
/**
* Generate a key with initialisation vector parameter derived from
* the password, salt, and iteration count we are currently initialised
* with.
*
* @param keySize the size of the key we want (in bits)
* @param ivSize the size of the iv we want (in bits)
* @return a ParametersWithIV object.
* @exception IllegalArgumentException if keySize + ivSize is larger than the base hash size.
*/
@Override
public CipherParameters generateDerivedParameters(int keySize, int ivSize) {
keySize = keySize / 8;
ivSize = ivSize / 8;
byte[] dKey = generateDerivedKey(keySize + ivSize);
return new ParametersWithIV(new KeyParameter(dKey, 0, keySize), dKey, keySize, ivSize);
}
use of org.gudy.bouncycastle.crypto.params.KeyParameter in project BiglyBT by BiglySoftware.
the class PKCS5S1ParametersGenerator method generateDerivedParameters.
/**
* Generate a key with initialisation vector parameter derived from
* the password, salt, and iteration count we are currently initialised
* with.
*
* @param keySize the size of the key we want (in bits)
* @param ivSize the size of the iv we want (in bits)
* @return a ParametersWithIV object.
* @exception IllegalArgumentException if keySize + ivSize is larger than the base hash size.
*/
@Override
public CipherParameters generateDerivedParameters(int keySize, int ivSize) {
keySize = keySize / 8;
ivSize = ivSize / 8;
if ((keySize + ivSize) > digest.getDigestSize()) {
throw new IllegalArgumentException("Can't generate a derived key " + (keySize + ivSize) + " bytes long.");
}
byte[] dKey = generateDerivedKey();
return new ParametersWithIV(new KeyParameter(dKey, 0, keySize), dKey, keySize, ivSize);
}
Aggregations