Question

Possible Duplicate:
Can RSACryptoServiceProvider (.NET’s RSA) use SHA256 for encryption (not signing) instead of SHA1?

When using RSACryptoServiceProvider for encryption the default hash algorithm obviously is SHA-1. How can I define another hash algorithm like SHA-512 when encrypting data (using the Encrypt method)? I did not find any property related to the hash algorithm.

Was it helpful?

Solution

RSACryptoServiceProvider will only let you set the hash function used with signing, by using one of the SignData() overloads. Unfortunately it doesn't look like there's any way to change the hash used by OAEP padding without using something like the CLRSecurity project.

If you look at the RSACng wrapper, you can set the EncryptionHashAlgorithm property. The default looks like it's SHA256. See this answer that @owelstead gave in the comments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top