当前位置: 首页>>代码示例>>C#>>正文


C# MD5CryptoServiceProvider类代码示例

本文整理汇总了C#中MD5CryptoServiceProvider的典型用法代码示例。如果您正苦于以下问题:C# MD5CryptoServiceProvider类的具体用法?C# MD5CryptoServiceProvider怎么用?C# MD5CryptoServiceProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MD5CryptoServiceProvider类属于命名空间,在下文中一共展示了MD5CryptoServiceProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetMd5Sum

    public static string GetMd5Sum(string str)
    {
        // First we need to convert the string into bytes, which
        // means using a text encoder.
        Encoder enc = System.Text.Encoding.Unicode.GetEncoder();

        // Create a buffer large enough to hold the string
        byte[] unicodeText = new byte[str.Length * 2];
        enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);

        // Now that we have a byte array we can ask the CSP to hash it
        MD5 md5 = new MD5CryptoServiceProvider();
        byte[] result = md5.ComputeHash(unicodeText);

        // Build the final string by converting each byte
        // into hex and appending it to a StringBuilder
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < result.Length; i++)
        {
            sb.Append(result[i].ToString("X2"));
        }

        // And return it
        return sb.ToString();
    }
开发者ID:ali-codehoppers,项目名称:simplicity-forms-estate-agent,代码行数:25,代码来源:Utility.cs

示例2: In

   public void In(
      [FriendlyName("Key", "The string to be used to generate the hash from.")]
      string Key,

      [FriendlyName("MD5 Hash", "The MD5 Hash generated by the Key.")]
      out string Hash
      )
   {
      if (Key != "")
      {
         UTF8Encoding ue = new UTF8Encoding();
         byte[] bytes = ue.GetBytes(Key);

         // encrypt bytes
         MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
         byte[] hashBytes = md5.ComputeHash(bytes);

         // Convert the encrypted bytes back to a string (base 16)
         string tmpHash = "";

         for (int i = 0; i < hashBytes.Length; i++)
         {
            tmpHash += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
         }

         Hash = tmpHash.PadLeft(32, '0');
      }
      else
      {
         uScriptDebug.Log("[Generate MD5 Hash] The Key provided was empty, returning an empty string for the MD5 Hash.", uScriptDebug.Type.Warning);
         Hash = "";
      }

   }
开发者ID:Zyanede,项目名称:Own-Projects,代码行数:34,代码来源:uScriptAct_GenerateMD5Hash.cs

示例3: Encrypt

    public string Encrypt(string ToEncrypt, bool useHasing)
    {
        byte[] keyArray;
        byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(ToEncrypt);

        string Key = "malkit";
        if (useHasing)
        {
            MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
            keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(Key));
            hashmd5.Clear();
        }
        else
        {
            keyArray = UTF8Encoding.UTF8.GetBytes(Key);
        }
        TripleDESCryptoServiceProvider tDes = new TripleDESCryptoServiceProvider();
        tDes.Key = keyArray;
        tDes.Mode = CipherMode.ECB;
        tDes.Padding = PaddingMode.PKCS7;
        ICryptoTransform cTransform = tDes.CreateEncryptor();
        byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
        tDes.Clear();
        return Convert.ToBase64String(resultArray, 0, resultArray.Length);
    }
开发者ID:riteshventurepact,项目名称:TAPD,代码行数:25,代码来源:EncryptDecrypt.cs

示例4: Decrypt

    public string Decrypt(string cypherString, bool useHasing)
    {
        byte[] keyArray;
        byte[] toDecryptArray = Convert.FromBase64String(cypherString.Replace(' ','+'));

        string key = "malkit";
        if (useHasing)
        {
            MD5CryptoServiceProvider hashmd = new MD5CryptoServiceProvider();
            keyArray = hashmd.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
            hashmd.Clear();
        }
        else
        {
            keyArray = UTF8Encoding.UTF8.GetBytes(key);
        }
        TripleDESCryptoServiceProvider tDes = new TripleDESCryptoServiceProvider();
        tDes.Key = keyArray;
        tDes.Mode = CipherMode.ECB;
        tDes.Padding = PaddingMode.PKCS7;
        ICryptoTransform cTransform = tDes.CreateDecryptor();
        try
        {
            byte[] resultArray = cTransform.TransformFinalBlock(toDecryptArray, 0, toDecryptArray.Length);
            tDes.Clear();
            return UTF8Encoding.UTF8.GetString(resultArray, 0, resultArray.Length);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
开发者ID:riteshventurepact,项目名称:TAPD,代码行数:32,代码来源:EncryptDecrypt.cs

示例5: MD5Encode

 /// <summary>
 /// MD5加密
 /// </summary>
 /// <param name="strOriginal"></param>
 /// <returns></returns>
 public static string MD5Encode(string strOriginal)
 {
     byte[] byteInput = UTF8Encoding.UTF8.GetBytes(strOriginal);
     MD5CryptoServiceProvider objMD5 = new MD5CryptoServiceProvider();
     byte[] byteOutput = objMD5.ComputeHash(byteInput);
     return BitConverter.ToString(byteOutput).Replace("-", "");
 }
开发者ID:chutinhha,项目名称:fixed-asset-system,代码行数:12,代码来源:EncodeHelper.cs

示例6: ComputeMD5

    public static string ComputeMD5(string value)
    {
        /*
         * Create the md5 crypt service provider
         */
        MD5 crypt = new MD5CryptoServiceProvider();
        StreamWriter pwd = new StreamWriter(new MemoryStream());
        pwd.Write(value);
        pwd.Flush();

        /*
         * Compute the hash code
         */
        pwd.BaseStream.Seek(0, SeekOrigin.Begin);
        byte[] cryptHash = crypt.ComputeHash(pwd.BaseStream);

        /*
         * Convert the result to hex
         */
        string result = "";

        int nLen = cryptHash.Length;
        for (int nPos = 0; nPos < nLen; nPos++)
        {
            byte cBuff = cryptHash[nPos];
            result += Convert((long)cBuff, 16);
        }

        return result.ToLower();
    }
开发者ID:kavallo,项目名称:E-Menu,代码行数:30,代码来源:MD5.cs

示例7: LogIn

    protected void LogIn(object sender, EventArgs e)
    {
        // Colecting data
        string email = TBEmail.Text;
        string password = TBPass.Text;

        // Hashing password
        MD5 md5 = new MD5CryptoServiceProvider();
        md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(password));
        password = Convert.ToBase64String(md5.Hash);

        // Checking login details
        Staff account = DBConnectivity.login(email, password);

        if (account != null)
        {
            // Loging OK
            Session["auth_email"] = account.email;
            Session["first_name"] = account.firstName;
            Session["access"] = account.access;
            Response.Redirect("~/Manage-Pets");
        }
        else
        {
            // Bad details
            ErrorMessage.Visible = true;
            FailureText.Text = "Bad credentials. Try again.";
        }
    }
开发者ID:knowbody,项目名称:fwp,代码行数:29,代码来源:Login.aspx.cs

示例8: Encrypt

    public static string Encrypt(string toEncrypt, bool useHashing)
    {
        byte[] keyArray;
        byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt);
        System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
        string key = (string)settingsReader.GetValue("search", typeof(string));
        if (useHashing)
        {
            MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
            keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
            hashmd5.Clear();
        }
        else
                    keyArray = UTF8Encoding.UTF8.GetBytes(key);

            TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
            tdes.Key = keyArray;
            tdes.Mode = CipherMode.ECB;
            tdes.Padding = PaddingMode.PKCS7;
            ICryptoTransform cTransform = tdes.CreateEncryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
            tdes.Clear();
            return Convert.ToBase64String(resultArray, 0, resultArray.Length);

        }   
开发者ID:gowrinath,项目名称:Public-Health-Care-System,代码行数:25,代码来源:encryption.cs

示例9: Decrypt

    /// <summary>
    /// Decrypt the given string using the specified key.
    /// </summary>
    /// <param name="strEncrypted">The string to be decrypted.</param>
    /// <param name="strKey">The decryption key.</param>
    /// <returns>The decrypted string.</returns>
    public static string Decrypt(string strEncrypted, string strKey)
    {
        try
        {
            TripleDESCryptoServiceProvider objDESCrypto = new TripleDESCryptoServiceProvider();
            MD5CryptoServiceProvider objHashMD5 = new MD5CryptoServiceProvider();

            byte[] byteHash, byteBuff;
            string strTempKey = strKey;

            byteHash = objHashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strTempKey));
            objHashMD5 = null;
            objDESCrypto.Key = byteHash;
            objDESCrypto.Mode = CipherMode.ECB; //CBC, CFB

            byteBuff = Convert.FromBase64String(strEncrypted);
            string strDecrypted = ASCIIEncoding.ASCII.GetString(objDESCrypto.CreateDecryptor().TransformFinalBlock(byteBuff, 0, byteBuff.Length));
            objDESCrypto = null;

            return strDecrypted;
        }
        catch (Exception ex)
        {
            return "Wrong Input. " + ex.Message;
        }
    }
开发者ID:Ndiya999,项目名称:Bulabula,代码行数:32,代码来源:SSTCryptographer.cs

示例10: In

    public void In(
      [FriendlyName("Key", "The string to be used to check against the provided MD5 hash.")]
      string Key,
      
      [FriendlyName("MD5 Hash", "The MD5 Hash to check the key against.")]
      string Hash
      )
    {
        if (Key != "" && Hash != "")
          {
         UTF8Encoding ue = new UTF8Encoding();
         byte[] bytes = ue.GetBytes(Key);

         // encrypt bytes
         MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
         byte[] hashBytes = md5.ComputeHash(bytes);

         // Convert the encrypted bytes back to a string (base 16)
         string tmpHash = "";

         for (int i = 0; i < hashBytes.Length; i++)
         {
            tmpHash += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
         }

         string finalHash = tmpHash.PadLeft(32, '0');

         if (finalHash == Hash)
         {
            m_GoodHash = true;
         }
          }
    }
开发者ID:Oxy949,项目名称:Obscended,代码行数:33,代码来源:uScriptAct_CheckMD5Hash.cs

示例11: Encrypt

    public static string Encrypt(string plainText )
    {
        string encrypted = null;
            try
            {
                byte[] inputBytes = ASCIIEncoding.ASCII.GetBytes(plainText);
                byte[] pwdhash = null;
                MD5CryptoServiceProvider hashmd5;

                //generate an MD5 hash from the password.
                //a hash is a one way encryption meaning once you generate
                //the hash, you cant derive the password back from it.
                hashmd5 = new MD5CryptoServiceProvider();
                pwdhash = hashmd5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(key));
                hashmd5 = null;

                // Create a new TripleDES service provider
                TripleDESCryptoServiceProvider tdesProvider = new TripleDESCryptoServiceProvider();
                tdesProvider.Key = pwdhash;
                tdesProvider.Mode = CipherMode.ECB;
                byte [] edata = tdesProvider.CreateEncryptor().TransformFinalBlock(inputBytes, 0, inputBytes.Length);
                encrypted = Convert.ToBase64String(	edata );

            }
            catch(Exception e)
            {
                string str = e.Message;
                throw ;
            }
            return encrypted;
    }
开发者ID:vibhutisuthar,项目名称:TEST,代码行数:31,代码来源:Tools.cs

示例12: md5method

 public static string md5method(string textoPlano)
 {
     byte[] data = System.Text.UTF8Encoding.ASCII.GetBytes(textoPlano);
     MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
     byte[] hashbyte = md5.ComputeHash(data, 0, data.Length);
     return BitConverter.ToString(hashbyte);
 }
开发者ID:jaratj87,项目名称:grn,代码行数:7,代码来源:Default.aspx.cs

示例13: Com

    private static string Com(Stream stream)
    {
        MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

        md5.ComputeHash(stream);

        byte[] hash = md5.Hash;

        if (hash == null)
        {
            _ecode = MD5ErrorCode.E_ComputeHash;

            return string.Empty;
        }

        StringBuilder sb = new StringBuilder();

        foreach (byte byt in hash)
        {

            sb.Append(String.Format("{0:X1}", byt));

        }

        string ret = sb.ToString();

        sb = null;

        return ret; 

    }
开发者ID:seenen,项目名称:HerosTechBak_Seenen,代码行数:31,代码来源:MD5.cs

示例14: MD5

            public static string MD5(string text)
            {
                string md5Hash;
                StringBuilder sb;
                byte[] textBytes;
                byte[] encodedBytes;
                MD5CryptoServiceProvider md5Provider;

                if (text == null) {
                    throw new ArgumentNullException("text");
                }

                sb = new StringBuilder();
                md5Provider = new MD5CryptoServiceProvider();
                textBytes = ASCIIEncoding.Default.GetBytes(text);
                encodedBytes = md5Provider.ComputeHash(textBytes);

                for (int i = 0; i < encodedBytes.Length; i++) {
                    sb.AppendFormat("{0:x2}", encodedBytes[i]);
                }

                md5Hash = sb.ToString();

                return md5Hash;
            }
开发者ID:gerc,项目名称:CloudPay,代码行数:25,代码来源:Cryptography.cs

示例15: HMACMD5

 public HMACMD5 (byte[] key) {
     m_hashName = "MD5"; 
     m_hash1 = new MD5CryptoServiceProvider();
     m_hash2 = new MD5CryptoServiceProvider(); 
     HashSizeValue = 128; 
     base.InitializeKey(key);
 } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:7,代码来源:HMACMD5.cs


注:本文中的MD5CryptoServiceProvider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。