1234567891011121314151617181920212223242526272829 |
- using System;
- using System.Collections.Generic;
- using System.Security.Cryptography;
- using System.Text;
- namespace CZFW.Core.Security
- {
- public static class SHA1Encrypt
- {
- public static string Encrypt(string str)
- {
- SHA1 md5Hash = SHA1.Create();
- // Convert the input string to a byte array and compute the hash.
- byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(str));
- // Create a new Stringbuilder to collect the bytes
- // and create a string.
- StringBuilder sBuilder = new StringBuilder();
- // Loop through each byte of the hashed data
- // and format each one as a hexadecimal string.
- for (int i = 0; i < data.Length; i++)
- {
- sBuilder.Append(data[i].ToString("X2"));
- }
- // Return the hexadecimal string.
- return sBuilder.ToString();
- }
- }
- }
|