Skip to content

Commit 77b8334

Browse files
committed
added use of OAEP and RSA/ECB/OAEPPadding to provide better support for SunJCE (relates to github #1277)
1 parent acd7f08 commit 77b8334

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

pkix/src/main/java/org/bouncycastle/operator/jcajce/OperatorHelper.java

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class OperatorHelper
6868

6969
asymmetricWrapperAlgNames.put(PKCSObjectIdentifiers.rsaEncryption, "RSA/ECB/PKCS1Padding");
7070
asymmetricWrapperAlgNames.put(OIWObjectIdentifiers.elGamalAlgorithm, "Elgamal/ECB/PKCS1Padding");
71+
asymmetricWrapperAlgNames.put(PKCSObjectIdentifiers.id_RSAES_OAEP, "RSA/ECB/OAEPPadding");
7172

7273
asymmetricWrapperAlgNames.put(CryptoProObjectIdentifiers.gostR3410_2001, "ECGOST3410");
7374

@@ -264,24 +265,43 @@ Cipher createSymmetricWrapper(ASN1ObjectIdentifier algorithm)
264265
AlgorithmParameters createAlgorithmParameters(AlgorithmIdentifier cipherAlgId)
265266
throws OperatorCreationException
266267
{
267-
AlgorithmParameters parameters;
268+
AlgorithmParameters parameters = null;
268269

269270
if (cipherAlgId.getAlgorithm().equals(PKCSObjectIdentifiers.rsaEncryption))
270271
{
271272
return null;
272273
}
273274

274-
try
275+
if (cipherAlgId.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSAES_OAEP))
275276
{
276-
parameters = helper.createAlgorithmParameters(cipherAlgId.getAlgorithm().getId());
277-
}
278-
catch (NoSuchAlgorithmException e)
279-
{
280-
return null; // There's a good chance there aren't any!
277+
try
278+
{
279+
parameters = helper.createAlgorithmParameters("OAEP");
280+
}
281+
catch (NoSuchAlgorithmException e)
282+
{
283+
// try below
284+
}
285+
catch (NoSuchProviderException e)
286+
{
287+
throw new OperatorCreationException("cannot create algorithm parameters: " + e.getMessage(), e);
288+
}
281289
}
282-
catch (NoSuchProviderException e)
290+
291+
if (parameters == null)
283292
{
284-
throw new OperatorCreationException("cannot create algorithm parameters: " + e.getMessage(), e);
293+
try
294+
{
295+
parameters = helper.createAlgorithmParameters(cipherAlgId.getAlgorithm().getId());
296+
}
297+
catch (NoSuchAlgorithmException e)
298+
{
299+
return null; // There's a good chance there aren't any!
300+
}
301+
catch (NoSuchProviderException e)
302+
{
303+
throw new OperatorCreationException("cannot create algorithm parameters: " + e.getMessage(), e);
304+
}
285305
}
286306

287307
try

0 commit comments

Comments
 (0)