Skip to content

Commit 581c10c

Browse files
committed
added setUnwrappingProvider()
1 parent c17830e commit 581c10c

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

pkix/src/main/java/org/bouncycastle/cms/jcajce/JceKeyAgreeRecipient.java

+30-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public abstract class JceKeyAgreeRecipient
5656
private PrivateKey recipientKey;
5757
protected EnvelopedDataHelper helper = new EnvelopedDataHelper(new DefaultJcaJceExtHelper());
5858
protected EnvelopedDataHelper contentHelper = helper;
59+
protected EnvelopedDataHelper unwrappingHelper = helper;
5960
private SecretKeySizeProvider keySizeProvider = new DefaultSecretKeySizeProvider();
6061
private AlgorithmIdentifier privKeyAlgID = null;
6162

@@ -74,6 +75,7 @@ public JceKeyAgreeRecipient setProvider(Provider provider)
7475
{
7576
this.helper = new EnvelopedDataHelper(new ProviderJcaJceExtHelper(provider));
7677
this.contentHelper = helper;
78+
this.unwrappingHelper = helper;
7779

7880
return this;
7981
}
@@ -88,6 +90,33 @@ public JceKeyAgreeRecipient setProvider(String providerName)
8890
{
8991
this.helper = new EnvelopedDataHelper(new NamedJcaJceExtHelper(providerName));
9092
this.contentHelper = helper;
93+
this.unwrappingHelper = helper;
94+
95+
return this;
96+
}
97+
98+
/**
99+
* Set the provider to use for unwrapping the content session key.
100+
*
101+
* @param provider provider to use.
102+
* @return this recipient.
103+
*/
104+
public JceKeyAgreeRecipient setUnwrappingProvider(Provider provider)
105+
{
106+
this.unwrappingHelper = new EnvelopedDataHelper(new ProviderJcaJceExtHelper(provider));
107+
108+
return this;
109+
}
110+
111+
/**
112+
* Set the provider to use for unwrapping the content session key.
113+
*
114+
* @param providerName the name of the provider to use.
115+
* @return this recipient.
116+
*/
117+
public JceKeyAgreeRecipient setUnwrappingProvider(String providerName)
118+
{
119+
this.unwrappingHelper = new EnvelopedDataHelper(new NamedJcaJceExtHelper(providerName));
91120

92121
return this;
93122
}
@@ -214,7 +243,7 @@ else if (CMSUtils.isGOST(keyEncAlg.getAlgorithm()))
214243
protected Key unwrapSessionKey(ASN1ObjectIdentifier wrapAlg, SecretKey agreedKey, ASN1ObjectIdentifier contentEncryptionAlgorithm, byte[] encryptedContentEncryptionKey)
215244
throws CMSException, InvalidKeyException, NoSuchAlgorithmException
216245
{
217-
Cipher keyCipher = helper.createCipher(wrapAlg);
246+
Cipher keyCipher = unwrappingHelper.createCipher(wrapAlg);
218247
keyCipher.init(Cipher.UNWRAP_MODE, agreedKey);
219248
return keyCipher.unwrap(encryptedContentEncryptionKey, helper.getBaseCipherName(contentEncryptionAlgorithm), Cipher.SECRET_KEY);
220249
}

0 commit comments

Comments
 (0)