Inadequate RSA Padding

Inadequate RSA padding in C#

Description

With PKCS#1 v1.5 RSA encryption, decryption errors or response times can reveal whether padding was valid. Unpadded RSA produces repeatable ciphertext and permits manipulation.

Potential impact

Revealing padding validity can compromise the data being decrypted.

Remediation

Choose OAEP with SHA-256 or stronger when both providers support it, and handle decryption failures uniformly.

Examples

Before

csharp
return rsa.Encrypt(data, RSAEncryptionPadding.Pkcs1);

After

csharp
return rsa.Encrypt(data, RSAEncryptionPadding.OaepSHA256);

The rsa.Encrypt call selects RSAEncryptionPadding.OaepSHA256. Match that setting on the decrypting side.

References