问题
When I go to the System.Security.Cryptography
namespace, I can only see SHA1
, SHA256
, HMACSHA1
etc classes there.
But actually, there is a SHA1Managed
class, as well as SHA256Managed
, which I don't see? When I write it out manually - everything works as expected.
Is this hidden intentionally? And what's the difference between simply instancing a managed version of those, versus for example calling their factory methods (SHA1.Create()
or SHA256.Create()
)? Are they the same thing?
回答1:
Can't give you an answer for the weird IntelliSense problem but have a look at the SHA1 and SHA1Managed implementations. SHA1 is just a base class. The implementation is exactly the same in this case. It has something to do with the FIPS certification. Managed versions don't use the native crypto libraries and therefor are not FIPS certified. There is a registry setting (FipsAlgorithmPolicy
) for customers which enforces FIPS compliance. If the registry setting is turned on you can't use the managed classes.
In your case it does not make any difference if you instanciate SHA1Managed
or use SHA1.Create()
. But it does make a difference if you need to meet the FIPS certification.
来源:https://stackoverflow.com/questions/65036928/why-are-classes-like-sha1managed-sha256managed-hidden-from-my-intellisense