Example usage for org.bouncycastle.asn1.pkcs PBEParameter getIterationCount

List of usage examples for org.bouncycastle.asn1.pkcs PBEParameter getIterationCount

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.pkcs PBEParameter getIterationCount.

Prototype

public BigInteger getIterationCount() 

Source Link

Usage

From source file:org.cryptacular.pbe.PBES1EncryptionScheme.java

License:Open Source License

/**
 * Creates a new instance with the given parameters.
 *
 * @param  alg  Describes hash/algorithm pair suitable for PBES1 scheme.
 * @param  params  Key generation function salt and iteration count.
 * @param  password  Password used to derive key.
 *//*from www .j  a  va  2s .  co m*/
public PBES1EncryptionScheme(final PBES1Algorithm alg, final PBEParameter params, final char[] password) {
    final byte[] salt = params.getSalt();
    final int iterations = params.getIterationCount().intValue();
    final PKCS5S1ParametersGenerator generator = new PKCS5S1ParametersGenerator(
            alg.getDigestSpec().newInstance());
    generator.init(PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(password), salt, iterations);
    setCipher(alg.getCipherSpec().newInstance());
    setCipherParameters(generator.generateDerivedParameters(KEY_LENGTH, IV_LENGTH));
}