App_Code/EncryptHelper.cs

(开头部分) 6KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
using System.IO;

namespace CommonLib
{
    public class EncryptHelper
    {
        /// <summary>
        /// 对字符串进行MD5或SHA1加密操作
        /// </summary>
        /// <param name="cleanString">明文字符串</param>
        /// <returns>加密后的字符串</returns>
        public static string Encrypt(string cleanString, string strPasswordFormat)
        {
            Byte[] clearBytes = new UnicodeEncoding().GetBytes(cleanString);
            Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName(strPasswordFormat)).ComputeHash(clearBytes);
            return BitConverter.ToString(hashedBytes);
        }



        //默认密钥向量    
        private static byte[] Keys = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
        
        /// <summary>    
        /// DES加密字符串    
        /// </summary>    
        /// <param name="encryptString">待加密的字符串</param>    
        /// <param name="encryptKey">加密密钥,要求为8位</param>    
        /// <returns>加密成功返回加密后的字符串,失败返回源串</returns>    
        public static string EncryptDES(string encryptString, string encryptKey)
        {
            try
            {
                byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
                byte[] rgbIV = Keys;
                byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
                DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
                MemoryStream mStream = new MemoryStream();
                CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey,

rgbIV), CryptoStreamMode.Write);
                cStream.Write(inputByteArray, 0, inputByteArray.Length);
                cStream.FlushFinalBlock();
                return Convert.ToBase64String(mStream.ToArray());
            }
            catch
            {
                return encryptString;
            }
        }

        /// <summary>    
        /// DES解密字符串    
        /// </summary>    
        /// <param name="decryptString">待解密的字符串</param>    
        /// <param name="decryptKey">解密密钥,要求为8位,和加密密钥相同</param>    
后面还有 92 行代码,购买后查看完整代码

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

AI 解读

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

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