org.bouncycastle.operator.bc.BcSymmetricKeyWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcpkix-jdk14 Show documentation
Show all versions of bcpkix-jdk14 Show documentation
The Bouncy Castle Java APIs for CMS, PKCS, EAC, TSP, CMP, CRMF, OCSP, and certificate generation. This jar contains APIs for JDK 1.4. The APIs can be used in conjunction with a JCE/JCA provider such as the one provided with the Bouncy Castle Cryptography APIs.
package org.bouncycastle.operator.bc;
import java.security.SecureRandom;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.crypto.Wrapper;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.crypto.params.ParametersWithRandom;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.OperatorException;
import org.bouncycastle.operator.SymmetricKeyWrapper;
public class BcSymmetricKeyWrapper
extends SymmetricKeyWrapper
{
private SecureRandom random;
private Wrapper wrapper;
private KeyParameter wrappingKey;
public BcSymmetricKeyWrapper(AlgorithmIdentifier wrappingAlgorithm, Wrapper wrapper, KeyParameter wrappingKey)
{
super(wrappingAlgorithm);
this.wrapper = wrapper;
this.wrappingKey = wrappingKey;
}
public BcSymmetricKeyWrapper setSecureRandom(SecureRandom random)
{
this.random = random;
return this;
}
public byte[] generateWrappedKey(GenericKey encryptionKey)
throws OperatorException
{
byte[] contentEncryptionKeySpec = OperatorUtils.getKeyBytes(encryptionKey);
if (random == null)
{
wrapper.init(true, wrappingKey);
}
else
{
wrapper.init(true, new ParametersWithRandom(wrappingKey, random));
}
return wrapper.wrap(contentEncryptionKeySpec, 0, contentEncryptionKeySpec.length);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy