com.fitbur.bouncycastle.cms.bc.BcKeyTransRecipient Maven / Gradle / Ivy
package com.fitbur.bouncycastle.cms.bc;
import com.fitbur.bouncycastle.asn1.x509.AlgorithmIdentifier;
import com.fitbur.bouncycastle.cms.CMSException;
import com.fitbur.bouncycastle.cms.KeyTransRecipient;
import com.fitbur.bouncycastle.crypto.CipherParameters;
import com.fitbur.bouncycastle.crypto.params.AsymmetricKeyParameter;
import com.fitbur.bouncycastle.operator.AsymmetricKeyUnwrapper;
import com.fitbur.bouncycastle.operator.OperatorException;
import com.fitbur.bouncycastle.operator.bc.BcRSAAsymmetricKeyUnwrapper;
public abstract class BcKeyTransRecipient
implements KeyTransRecipient
{
private AsymmetricKeyParameter recipientKey;
public BcKeyTransRecipient(AsymmetricKeyParameter recipientKey)
{
this.recipientKey = recipientKey;
}
protected CipherParameters extractSecretKey(AlgorithmIdentifier keyEncryptionAlgorithm, AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedEncryptionKey)
throws CMSException
{
AsymmetricKeyUnwrapper unwrapper = new BcRSAAsymmetricKeyUnwrapper(keyEncryptionAlgorithm, recipientKey);
try
{
return CMSUtils.getBcKey(unwrapper.generateUnwrappedKey(encryptedKeyAlgorithm, encryptedEncryptionKey));
}
catch (OperatorException e)
{
throw new CMSException("exception unwrapping key: " + e.getMessage(), e);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy