Search in sources :

Example 1 with OpenSSLPBEParametersGenerator

use of org.gudy.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator 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);
}
Also used : KeyParameter(org.gudy.bouncycastle.crypto.params.KeyParameter) OpenSSLPBEParametersGenerator(org.gudy.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator)

Aggregations

OpenSSLPBEParametersGenerator (org.gudy.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator)1 KeyParameter (org.gudy.bouncycastle.crypto.params.KeyParameter)1