Search in sources :

Example 1 with OpenSSLPBEParametersGenerator

use of org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator in project XobotOS by xamarin.

the class PEMUtilities method getKey.

private static SecretKey getKey(char[] password, String algorithm, int keyLength, byte[] salt, boolean des2) {
    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 : SecretKeySpec(javax.crypto.spec.SecretKeySpec) KeyParameter(org.bouncycastle.crypto.params.KeyParameter) OpenSSLPBEParametersGenerator(org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator)

Aggregations

SecretKeySpec (javax.crypto.spec.SecretKeySpec)1 OpenSSLPBEParametersGenerator (org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator)1 KeyParameter (org.bouncycastle.crypto.params.KeyParameter)1