String plaintext = "plaintext ";
Byte [] srcbuffer = system. Text. encoding. utf8.getbytes (plaintext );
Hashalgorithm hash = hashalgorithm. Create ("sha1"); // If the parameter is changed to "MD5", MD5 encryption is performed. Case Insensitive.
Byte [] destbuffer = hash. computehash (srcbuffer );
String hashedtext = bitconverter. tostring (destbuffer). Replace ("-","");
YesHashalgorithmThe namespace of this class isSystem. Security. Cryptography. Only two methods are used:CreateAndComputehash, Computehash returns byte []. To show the result, it is converted to a string. After conversion, the sha1 result is the same as that described in the previous section.
You can also useSha1managedAndSha1cryptoserviceproviderBut we recommend that you use the method described in this article because it does not involve the class name and needs to be changed.Algorithm, You only need to change the create string parameter.