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


C# MD5CryptoServiceProvider.Clear方法代码示例

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


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

示例1: Decrypt

        /// <summary>
        /// DeCrypt a string using dual encryption method. Return a DeCrypted clear string
        /// </summary>
        /// <param name="cipherString">encrypted string</param>
        /// <param name="useHashing">Did you use hashing to encrypt this data? pass true is yes</param>
        /// <returns></returns>
        public static string Decrypt(string cipherString, bool useHashing)
        {
            byte[] keyArray;
            byte[] toEncryptArray = Convert.FromBase64String(cipherString);

            System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
            //Get your key from config file to open the lock!
            string key = (string)settingsReader.GetValue("Security key", 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.CreateDecryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

            tdes.Clear();
            return UTF8Encoding.UTF8.GetString(resultArray);
        }
开发者ID:xyztdanid4,项目名称:szakdolgozat,代码行数:35,代码来源:des.cs

示例2: MD5Encrypt

 //md5 encrypt
 public static string MD5Encrypt(string toEncrypt, string securityKey, bool useHashing)
 {
     string retVal = string.Empty;
             try {
                     byte[] keyArray;
                     byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes (toEncrypt);
                     ValidateInput (toEncrypt);
                     ValidateInput (securityKey);
                     if (useHashing) {
                             MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider ();
                             keyArray = hashmd5.ComputeHash (UTF8Encoding.UTF8.GetBytes (securityKey));
                             hashmd5.Clear ();
                     } else {
                             keyArray = UTF8Encoding.UTF8.GetBytes (securityKey);
                     }
                     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 ();
                     retVal = Convert.ToBase64String (resultArray, 0, resultArray.Length);
             } catch (Exception ex) {
                     Debug.Log (ex.Message);
             }
             return retVal;
 }
开发者ID:finian826,项目名称:Unity-A-Z,代码行数:29,代码来源:DataEncryption.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: 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

示例6: Encrypt

        public static string Encrypt(string toEncrypt, string securityKey, bool useHashing)
        {
            byte[] keyArray;
            byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt);

            string key = securityKey;

            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.CBC;
            //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:xyztdanid4,项目名称:szakdolgozat,代码行数:27,代码来源:des.cs

示例7: Encrypt

    public Encrypt()
    {
        mCSP = new TripleDESCryptoServiceProvider();
        strKey = "5EAGLES";
        MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
        keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(strKey));
        hashmd5.Clear();

        mCSP.Key = keyArray;
        mCSP.Mode = CipherMode.ECB;
        mCSP.Padding = PaddingMode.PKCS7;
    }
开发者ID:jackiechou,项目名称:thegioicuaban.com,代码行数:12,代码来源:Encrypt.cs

示例8: Decrypt

    public static string Decrypt(string cipherString, bool useHashing)
    {
        /*
         *  Reference to: Syed Moshiur - Software Developer
         *  http://www.codeproject.com/Articles/14150/Encrypt-and-Decrypt-Data-with-C
         *
         */
        byte[] keyArray;
        //get the byte code of the string

        byte[] toEncryptArray = Convert.FromBase64String(cipherString);

        System.Configuration.AppSettingsReader settingsReader =
                                            new AppSettingsReader();
        //Get your key from config file to open the lock!
        string key = (string)settingsReader.GetValue("SecurityKey",
                                                     typeof(String));

        if (useHashing)
        {
            //if hashing was used get the hash code with regards to your key
            MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
            keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
            //release any resource held by the MD5CryptoServiceProvider

            hashmd5.Clear();
        }
        else
        {
            //if hashing was not implemented get the byte code of the key
            keyArray = UTF8Encoding.UTF8.GetBytes(key);
        }

        TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
        //set the secret key for the tripleDES algorithm
        tdes.Key = keyArray;
        //mode of operation. there are other 4 modes.
        //We choose ECB(Electronic code Book)

        tdes.Mode = CipherMode.ECB;
        //padding mode(if any extra byte added)
        tdes.Padding = PaddingMode.PKCS7;

        ICryptoTransform cTransform = tdes.CreateDecryptor();
        byte[] resultArray = cTransform.TransformFinalBlock(
                             toEncryptArray, 0, toEncryptArray.Length);
        //Release resources held by TripleDes Encryptor
        tdes.Clear();
        //return the Clear decrypted TEXT
        return UTF8Encoding.UTF8.GetString(resultArray);
    }
开发者ID:nathard,项目名称:EmployeeMembershipCRM,代码行数:51,代码来源:Default.aspx.cs

示例9: GetMD5

 /// <summary>
 /// Md5 加密算法
 /// </summary>
 /// <param name="sDataIn">需要加密的内容</param>
 /// <returns>加密后的结果</returns>
 public static string GetMD5(string sDataIn)
 {
     MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
     byte[] bytValue, bytHash;
     bytValue = System.Text.Encoding.UTF8.GetBytes(sDataIn);
     bytHash = md5.ComputeHash(bytValue);
     md5.Clear();
     string sTemp = "";
     for (int i = 0; i < bytHash.Length; i++)
     {
         sTemp += bytHash[i].ToString("X").PadLeft(2, '0');
     }
     return sTemp.ToLower();
 }
开发者ID:Bonkebo,项目名称:schoolboy,代码行数:19,代码来源:CommentHelper.cs

示例10: Encrypt

  public string Encrypt(string toEncrypt)
  {
    byte[] keyArray;
    byte[] toEncryptArray = UTF8Encoding.BigEndianUnicode.GetBytes(toEncrypt);
    bool useHashing = false;

    //System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
    // Get the key from config file

    //string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
    string key = "MPcrypto";
    //System.Windows.Forms.MessageBox.Show(key);
    //If hashing use get hashcode regards to your key
    if (useHashing)
    {
      MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
      keyArray = hashmd5.ComputeHash(UTF8Encoding.BigEndianUnicode.GetBytes(key));
      //Always release the resources and flush data
      // of the Cryptographic service provide. Best Practice

      hashmd5.Clear();
    }
    else
      keyArray = UTF8Encoding.BigEndianUnicode.GetBytes(key);

    TripleDESCryptoServiceProvider tdes =
      new TripleDESCryptoServiceProvider();
    //set the secret key for the tripleDES algorithm
    tdes.Key = keyArray;
    //mode of operation. there are other 4 modes.
    //We choose ECB(Electronic code Book)
    tdes.Mode = CipherMode.ECB;
    //padding mode(if any extra byte added)

    tdes.Padding = PaddingMode.PKCS7;

    ICryptoTransform cTransform = tdes.CreateEncryptor();
    //transform the specified region of bytes array to resultArray
    byte[] resultArray =
      cTransform.TransformFinalBlock(toEncryptArray, 0,
                                     toEncryptArray.Length);
    //Release resources held by TripleDes Encryptor
    tdes.Clear();
    //Return the encrypted data into unreadable string format
    return Convert.ToBase64String(resultArray, 0, resultArray.Length);
  }
开发者ID:arangas,项目名称:MediaPortal-1,代码行数:46,代码来源:EncryptDecrypt.cs

示例11: Decrypt

    public static string Decrypt(string cipherString, bool useHashing)
    {
        byte[] keyArray;
        //get the byte code of the string

        byte[] toEncryptArray = Convert.FromBase64String(cipherString);

        string key = ConfigurationManager.AppSettings["EncryptKey"];

        if (useHashing)
        {
            //if hashing was used get the hash code with regards to your key
            MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
            keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
            //release any resource held by the MD5CryptoServiceProvider

            hashmd5.Clear();
        }
        else
        {
            //if hashing was not implemented get the byte code of the key
            keyArray = UTF8Encoding.UTF8.GetBytes(key);
        }

        TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
        //set the secret key for the tripleDES algorithm
        tdes.Key = keyArray;
        //mode of operation. there are other 4 modes.
        //We choose ECB(Electronic code Book)

        tdes.Mode = CipherMode.ECB;
        //padding mode(if any extra byte added)
        tdes.Padding = PaddingMode.PKCS7;

        ICryptoTransform cTransform = tdes.CreateDecryptor();
        byte[] resultArray = cTransform.TransformFinalBlock(
                             toEncryptArray, 0, toEncryptArray.Length);
        //Release resources held by TripleDes Encryptor
        tdes.Clear();
        //return the Clear decrypted TEXT
        return UTF8Encoding.UTF8.GetString(resultArray);
    }
开发者ID:ayaniv,项目名称:PostAroundMe,代码行数:42,代码来源:Tools.cs

示例12: Encrypt

 public static string Encrypt(string text)
 {
     //1、创建MD5对象
     MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
     //2、将字符编码为一个字节序列
     byte[] data = Encoding.Default.GetBytes(text);
     //3、计算data字节数组的哈希值 
     byte[] md5data = md5.ComputeHash(data);
     //4、释放MD5对象中的所有资源
     md5.Clear();
     //5、创建字符存储器并初始化
     StringBuilder str = new StringBuilder();
     str.Append(string.Empty);
     //6、存储加密字符
     for (int i = 0; i < md5data.Length - 1; i++)
     {
         str.Append(md5data[i].ToString("x").PadLeft(2, '0'));
     }
     //7、返回经过MD5加密过后的字符串
     return str.ToString();
 }
开发者ID:zhutaorun,项目名称:ACGCard-for-Unity3D,代码行数:21,代码来源:MD5.cs

示例13: EncryptData

 public static string EncryptData(string Message, string passphrase)
 {
     byte[] Results;
     System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
     MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
     byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(passphrase));
     TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();
     TDESAlgorithm.Key = TDESKey;
     TDESAlgorithm.Mode = CipherMode.ECB;
     TDESAlgorithm.Padding = PaddingMode.PKCS7;
     byte[] DataToEncrypt = UTF8.GetBytes(Message);
     try
     {
         ICryptoTransform Encryptor = TDESAlgorithm.CreateEncryptor();
         Results = Encryptor.TransformFinalBlock(DataToEncrypt, 0, DataToEncrypt.Length);
     }
     finally
     {
         TDESAlgorithm.Clear();
         HashProvider.Clear();
     }
     return Convert.ToBase64String(Results);
 }
开发者ID:nagyist,项目名称:ranjance26-HealthReunionProviderPortal,代码行数:23,代码来源:EncryptDecrypt.cs

示例14: DecryptString

    public static string DecryptString(string passphrase, string Message)
    {
        byte[] Results;
        UTF8Encoding UTF8 = new UTF8Encoding();

        MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
        byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(passphrase));

        TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();

        TDESAlgorithm.Key = TDESKey;
        TDESAlgorithm.Mode = CipherMode.ECB;
        TDESAlgorithm.Padding = PaddingMode.PKCS7;

        byte[] DataToDecrypt = Convert.FromBase64String(Message);

        try
        {
            ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor();
            Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length);
        }
        catch (Exception ex)
        {
            TDESAlgorithm.Clear();
            HashProvider.Clear();
            return ex.ToString();
        }
        finally
        {
            TDESAlgorithm.Clear();
            HashProvider.Clear();
        }
        return UTF8.GetString(Results);
    }
开发者ID:hjupter,项目名称:CloudGoodsSDK,代码行数:34,代码来源:WebserviceCalls.cs

示例15: HashString

    /// <summary>
    /// HashString(string Value)用于将密码加密
    /// 将Value用MD5加密,返回加密后的字串
    /// </summary>
    public static string HashString(string Value)
    {
        byte[] bytValue;
        byte[] bytHash;

        MD5CryptoServiceProvider mhash;
        mhash = new MD5CryptoServiceProvider();

        // Convert the original string to array of Bytes
        bytValue = System.Text.Encoding.UTF8.GetBytes(Value);

        // Compute the Hash, returns an array of Bytes
        bytHash = mhash.ComputeHash(bytValue);

        mhash.Clear();

        // Return a base 64 encoded string of the Hash value
        return Convert.ToBase64String(bytHash);
    }
开发者ID:tedi3231,项目名称:DMCProject,代码行数:23,代码来源:common.cs


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