Example usage for org.bouncycastle.crypto.generators OpenSSLPBEParametersGenerator generateDerivedParameters

List of usage examples for org.bouncycastle.crypto.generators OpenSSLPBEParametersGenerator generateDerivedParameters

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.generators OpenSSLPBEParametersGenerator generateDerivedParameters.

Prototype

public CipherParameters generateDerivedParameters(int keySize, int ivSize) 

Source Link

Document

Generate a key with initialisation vector parameter derived from the password, salt, and iteration count we are currently initialised with.

Usage

From source file:edu.wisc.doit.tcrypt.BouncyCastleFileEncrypter.java

License:Apache License

protected ParametersWithIV generateParameters() throws InvalidCipherTextException, IOException {
    //Generate a random password
    final byte[] passwordBytes = new byte[PASSWORD_LENGTH];
    SECURE_RANDOM.nextBytes(passwordBytes);
    final byte[] passwordBase64Bytes = Base64.encodeBase64(passwordBytes);
    final String passwordBase64String = new String(passwordBase64Bytes, CHARSET);

    //Generate a random salt
    final byte[] saltBytes = new byte[SALT_LENGTH];
    SECURE_RANDOM.nextBytes(saltBytes);//  ww w.  j  a  va  2 s.c om

    //Generate key & iv
    final OpenSSLPBEParametersGenerator generator = new OpenSSLPBEParametersGenerator();
    generator.init(PBEParametersGenerator.PKCS5PasswordToBytes(passwordBase64String.toCharArray()), saltBytes);
    return (ParametersWithIV) generator.generateDerivedParameters(KEY_LENGTH, IV_LENGTH);
}