use of com.github.zhenwei.core.crypto.io.CipherOutputStream in project LinLong-Java by zhenwei1108.
the class BcPKCS12PBEOutputEncryptorBuilder method build.
public OutputEncryptor build(final char[] password) {
if (random == null) {
random = new SecureRandom();
}
final byte[] salt = new byte[20];
random.nextBytes(salt);
final PKCS12PBEParams pbeParams = new PKCS12PBEParams(salt, iterationCount);
CipherParameters params = PKCS12PBEUtils.createCipherParameters(algorithm, digest, engine.getBlockSize(), pbeParams, password);
engine.init(true, params);
return new OutputEncryptor() {
public AlgorithmIdentifier getAlgorithmIdentifier() {
return new AlgorithmIdentifier(algorithm, pbeParams);
}
public OutputStream getOutputStream(OutputStream out) {
return new CipherOutputStream(out, engine);
}
public GenericKey getKey() {
return new GenericKey(new AlgorithmIdentifier(algorithm, pbeParams), PKCS12ParametersGenerator.PKCS12PasswordToBytes(password));
}
};
}
Aggregations