create RsaCryptoserviceProvider again

652 views Asked by At

I'm working with RSACryptoServiceProvider and I looked at examples on some book and on the Internet. In all the examples, a new instance of the type is being created in every method it is being used.

Is it not recommended to create only one RSACryptoServiceProvider instance and reuse it in all methods?

1

There are 1 answers

3
blowdart On

No - create your own each time, otherwise, once you start using different keys everything is going to go horribly wrong, or if you try to iterate through and need to decrypt something else. Furthermore it has thread safety problems.