I’m receiving a CryptographicException “Bad Hash.\r\n” from the code below when I call CreateSignature. Any ideas as to what might be causing this?
RSAPKCS1SignatureFormatter RSAFormatter =
new RSAPKCS1SignatureFormatter(new RSACryptoServiceProvider());
RSAFormatter.SetHashAlgorithm("SHA256");
byte[] signedHash = RSAFormatter.CreateSignature(myHash);
Your code snippet does not show how you get myHash but my guess is that it is not a 32 byte array. From MSDN:
Try defining your myHash like this: (Just an ugly sample here)
When i ran your code with a hash of any other size i got the same exact error. Running with the array defined above, 256 bits or 32 bytes, it worked.