Clothes.Comment/SHAEncryption.cs

(完整代码) 1KB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Clothes.Comment
{
   public class SHAEncryption
    {
        /// <summary>
        /// 散列加密(不可逆),加密失败时返回源字符串
        /// </summary>
        /// <param name="input">待加密的字符串</param>
        /// <returns>返回40个字符</returns>
        public string SHA1Encrypt(string input)
        {
            // 字符串为空
            if (string.IsNullOrWhiteSpace(input))
                return string.Empty;
            // 尝试加密
            byte[] byteArray = Encoding.UTF8.GetBytes(input);
            string ciphertext;
            try
            {
                byte[] cipherByte;
                using (SHA1Managed sha1 = new SHA1Managed())
                {
                    cipherByte = sha1.ComputeHash(byteArray);
                }
                ciphertext = Convert.ToBase64String(cipherByte);
            }
            catch (Exception ex)
            {
                //LogHelper.Error("数据加密失败", ex);
                return input;
            }
            // 返回
            return ciphertext;
        }

    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。