Creating RSA or RSACryptoServiceProvider object in .Net 4.6 is defaulting KeyExchangeAlgorithm RSA-PKCS1-KeyEx which supports only OaepSHA1 padding.
Getting "Specified padding mode is not valid for this algorithm" on trying to use other padding like "OaepSHA256".
Is there a way to override algorithm in RSA object to an algorithm that supports this padding to make it supportive for all paddings.
UPDATE RSACng works. In my scenario I am using containerkey to store private key in the machine using RSACryptoServiceProvider to retrieve private key when required using containerkey name. As a workaround to use RSACng I am importing properties exporting from RSACryptoServiceProvider object like shown below. Is there a better way to do this?
using (var rsa = new RSACryptoServiceProvider(cspParams))
{
using(var rsaCng = new RSACng())
{
rsaCng.ImportParameters(rsa.ExportParameters(true));
decryptedResult = rsaCng.Decrypt(encryotedText, RSAEncryptionPadding.OaepSHA256)
}
}
