Example usage for org.bouncycastle.crypto PBEParametersGenerator init

List of usage examples for org.bouncycastle.crypto PBEParametersGenerator init

Introduction

In this page you can find the example usage for org.bouncycastle.crypto PBEParametersGenerator init.

Prototype

public void init(byte[] password, byte[] salt, int iterationCount) 

Source Link

Document

initialise the PBE generator.

Usage

From source file:org.springframework.security.crypto.encrypt.BouncyCastleAesBytesEncryptor.java

License:Apache License

BouncyCastleAesBytesEncryptor(String password, CharSequence salt, BytesKeyGenerator ivGenerator) {
    if (ivGenerator.getKeyLength() != 16) {
        throw new IllegalArgumentException("ivGenerator key length != block size 16");
    }/*from   ww w. j av  a 2 s .com*/
    this.ivGenerator = ivGenerator;
    PBEParametersGenerator keyGenerator = new PKCS5S2ParametersGenerator();
    byte[] pkcs12PasswordBytes = PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(password.toCharArray());
    keyGenerator.init(pkcs12PasswordBytes, Hex.decode(salt), 1024);
    this.secretKey = (KeyParameter) keyGenerator.generateDerivedParameters(256);
}