@@ -56,6 +56,7 @@ public abstract class JceKeyAgreeRecipient
56
56
private PrivateKey recipientKey ;
57
57
protected EnvelopedDataHelper helper = new EnvelopedDataHelper (new DefaultJcaJceExtHelper ());
58
58
protected EnvelopedDataHelper contentHelper = helper ;
59
+ protected EnvelopedDataHelper unwrappingHelper = helper ;
59
60
private SecretKeySizeProvider keySizeProvider = new DefaultSecretKeySizeProvider ();
60
61
private AlgorithmIdentifier privKeyAlgID = null ;
61
62
@@ -74,6 +75,7 @@ public JceKeyAgreeRecipient setProvider(Provider provider)
74
75
{
75
76
this .helper = new EnvelopedDataHelper (new ProviderJcaJceExtHelper (provider ));
76
77
this .contentHelper = helper ;
78
+ this .unwrappingHelper = helper ;
77
79
78
80
return this ;
79
81
}
@@ -88,6 +90,33 @@ public JceKeyAgreeRecipient setProvider(String providerName)
88
90
{
89
91
this .helper = new EnvelopedDataHelper (new NamedJcaJceExtHelper (providerName ));
90
92
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 ));
91
120
92
121
return this ;
93
122
}
@@ -214,7 +243,7 @@ else if (CMSUtils.isGOST(keyEncAlg.getAlgorithm()))
214
243
protected Key unwrapSessionKey (ASN1ObjectIdentifier wrapAlg , SecretKey agreedKey , ASN1ObjectIdentifier contentEncryptionAlgorithm , byte [] encryptedContentEncryptionKey )
215
244
throws CMSException , InvalidKeyException , NoSuchAlgorithmException
216
245
{
217
- Cipher keyCipher = helper .createCipher (wrapAlg );
246
+ Cipher keyCipher = unwrappingHelper .createCipher (wrapAlg );
218
247
keyCipher .init (Cipher .UNWRAP_MODE , agreedKey );
219
248
return keyCipher .unwrap (encryptedContentEncryptionKey , helper .getBaseCipherName (contentEncryptionAlgorithm ), Cipher .SECRET_KEY );
220
249
}
0 commit comments