コード例 #1
0
 private static string dESDecrypt(string pToDecrypt)
 {
     if (Base64Util.IsBase64Formatted(pToDecrypt))  //未加密返回原数值
     {
         try
         {
             string Key = "DKMAB5DE";//加密密钥必须为8
             DESCryptoServiceProvider des = new DESCryptoServiceProvider();
             byte[] inputByteArray        = new byte[pToDecrypt.Length / 2];
             for (int x = 0; x < pToDecrypt.Length / 2; x++)
             {
                 int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
                 inputByteArray[x] = (byte)i;
             }
             des.Key = ASCIIEncoding.ASCII.GetBytes(Key);
             des.IV  = ASCIIEncoding.ASCII.GetBytes(Key);
             MemoryStream ms = new MemoryStream();
             CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
             cs.Write(inputByteArray, 0, inputByteArray.Length);
             cs.FlushFinalBlock();
             StringBuilder ret = new StringBuilder();
             return(System.Text.Encoding.ASCII.GetString(ms.ToArray()));
         }
         catch
         {
             return(pToDecrypt);
         }
     }
     else
     {
         return(pToDecrypt);
     }
 }
コード例 #2
0
 private static string getMD5ToBase64(string str)
 {
     if (!Base64Util.IsBase64Formatted(str))
     {
         MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
         byte[] message;
         message = Encoding.Default.GetBytes(str);
         md5.ComputeHash(message).ToString();
         return(Convert.ToBase64String(md5.Hash));
     }
     else
     {
         return(str);
     }
 }