Exemplo n.º 1
0
 /// <summary>
 /// 解密数据
 /// </summary>
 /// <param name="Text"></param>
 /// <param name="sKey"></param>
 /// <returns></returns>
 public static string Decrypt(string Text, string sKey)
 {
     try
     {
         DESCryptoServiceProvider des = new DESCryptoServiceProvider();
         int len;
         len = Text.Length / 2;
         byte[] inputByteArray = new byte[len];
         int    x, i;
         for (x = 0; x < len; x++)
         {
             i = Convert.ToInt32(Text.Substring(x * 2, 2), 16);
             inputByteArray[x] = (byte)i;
         }
         string md5SKey = MD5Helper.Get32MD5One(sKey).Substring(0, 8);
         des.Key = ASCIIEncoding.ASCII.GetBytes(md5SKey);
         des.IV  = ASCIIEncoding.ASCII.GetBytes(md5SKey);
         System.IO.MemoryStream ms = new System.IO.MemoryStream();
         CryptoStream           cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
         cs.Write(inputByteArray, 0, inputByteArray.Length);
         cs.FlushFinalBlock();
         return(Encoding.Default.GetString(ms.ToArray()));
     }
     catch { return("error"); }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 验证用户密码
        /// </summary>
        /// <param name="password">原始密码</param>
        /// <param name="secretkey">加密密钥</param>
        /// <param name="userPassword">用户验证密码</param>
        /// <returns></returns>
        public static bool VerifyPassword(string password, string secretKey, string userPassword)
        {
            string dbPassword = MD5Helper.Get32MD5One(DESEncrypt.Encrypt(MD5Helper.Get32MD5One(password).ToLower(), secretKey).ToLower()).ToLower();

            if (dbPassword == userPassword)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 加密数据
 /// </summary>
 /// <param name="Text"></param>
 /// <param name="sKey"></param>
 /// <returns></returns>
 public static string Encrypt(string Text, string sKey)
 {
     try
     {
         DESCryptoServiceProvider des = new DESCryptoServiceProvider();
         byte[] inputByteArray;
         inputByteArray = Encoding.Default.GetBytes(Text);
         string md5SKey = MD5Helper.Get32MD5One(sKey).Substring(0, 8);
         des.Key = ASCIIEncoding.ASCII.GetBytes(md5SKey);
         des.IV  = ASCIIEncoding.ASCII.GetBytes(md5SKey);
         System.IO.MemoryStream ms = new System.IO.MemoryStream();
         CryptoStream           cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
         cs.Write(inputByteArray, 0, inputByteArray.Length);
         cs.FlushFinalBlock();
         StringBuilder ret = new StringBuilder();
         foreach (byte b in ms.ToArray())
         {
             ret.AppendFormat("{0:X2}", b);
         }
         return(ret.ToString());
     }
     catch { return("error"); }
 }
Exemplo n.º 4
0
        /// <summary>
        /// 生成密码
        /// </summary>
        /// <param name="password">原始密码</param>
        /// <param name="secretkey">加密密钥</param>
        /// <returns></returns>
        public static string CreatePassword(string password, string secretKey)
        {
            string md5Password = MD5Helper.Get32MD5One(DESEncrypt.Encrypt(MD5Helper.Get32MD5One(password).ToLower(), secretKey).ToLower()).ToLower();

            return(md5Password);
        }