added use of WRAP_MODE for RSA
@@ -523,9 +523,19 @@ public TlsEncryptor createEncryptor(TlsCertificate certificate)
try
{
Cipher c = createRSAEncryptionCipher();
+ // try wrap mode first - strictly speaking this is the correct one to use.
+ try
+ {
+ c.init(Cipher.WRAP_MODE, pubKeyRSA, getSecureRandom());
+ return c.doFinal(input, inOff, length);
+ }
+ catch (Exception e)
+ {
+ // okay, maybe the provider does not support wrap mode.
c.init(Cipher.ENCRYPT_MODE, pubKeyRSA, getSecureRandom());
return c.doFinal(input, inOff, length);
}
+ }
catch (GeneralSecurityException e)
{
/*
