Reputation: 1734
You receive a System.Security.Cryptography.CryptographicException when a decryption fails because the key is wrong.
How does one avoid it? Is there a built-in solution that preferably looks like this?
if (someClass.TryDecrypt(encrypted key, out var result)) {
//use result
}
else {
//fail like the world hasn't ended yet.
}
Upvotes: 0
Views: 112
Reputation: 1
The correct way to handle this situation is to catch
the exception.
If your code is referred to a server-side environment, and you want to mitigate the risk of crashing your server because of the considerable amount of requests that may income (e.g. DoS), you might set an interval between the requests incoming from the same IP Address, for example.
Upvotes: 0