當前位置: 首頁>>代碼示例>>C#>>正文


C# SHA1Managed.Clear方法代碼示例

本文整理匯總了C#中System.Security.Cryptography.SHA1Managed.Clear方法的典型用法代碼示例。如果您正苦於以下問題:C# SHA1Managed.Clear方法的具體用法?C# SHA1Managed.Clear怎麽用?C# SHA1Managed.Clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Security.Cryptography.SHA1Managed的用法示例。


在下文中一共展示了SHA1Managed.Clear方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Encrypt_static

        /// <summary>
        /// SHA1Managed 算法的哈希值大小為 160 位
        /// 此類型的任何公共static成員都是線程安全的。但不保證所有實例成員都是線程安全的
        /// </summary>
        private static string Encrypt_static(string clearText, Encoding encode)
        {
            SHA1 sha = null;
            try
            {
                byte[] originalBytes = encode.GetBytes(clearText); //Encoding.UTF8.GetBytes(clearText);

                sha = new SHA1Managed();
                byte[] data = sha.ComputeHash(originalBytes);

                //return BitConverter.ToString(data); //將指定的字節數組的每個元素的數值轉換為它的等效十六進製字符串表示形式
                StringBuilder builder = new StringBuilder();
                foreach (var item in data)
                {
                    builder.Append(item.ToString("X2"));//將該哈希作為 32 字符的十六進製格式字符串返回
                }

                return builder.ToString();
            }
            catch (ArgumentNullException) { return clearText; }
            catch (EncoderFallbackException) { return clearText; }
            catch (ObjectDisposedException) { return clearText; }
            catch (InvalidOperationException) { return clearText; }
            catch (Exception) { return clearText; }
            finally
            {
                if (sha != null)
                {
                    sha.Clear();
                    sha.Dispose();
                }

                sha = null;
            }
        }
開發者ID:RoseLiu,項目名稱:OnePieceSolution,代碼行數:39,代碼來源:SHA1ManagedClass.cs

示例2: GetSHA1

		public static string GetSHA1(string source)
		{
			var sha1 = new SHA1Managed();
			var bytes = sha1.ComputeHash(Encoding.UTF8.GetBytes(source));
			var result = BitConverter.ToString(bytes).Replace("-", string.Empty).ToLower();
			sha1.Clear();
			return result;
		}
開發者ID:cuteribs,項目名稱:Cuteribs.D3Armory,代碼行數:8,代碼來源:Helper.cs

示例3: SHA1Hash

        /// <summary>
        /// Encrypt a string depend on sha256 algorithm
        /// </summary>
        /// <param name="input"></param>
        /// <returns>Encrypted string.</returns>
        public static byte[] SHA1Hash(string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return null;
            }

            SHA1Managed hashAlgorithm = new SHA1Managed();
            try
            {
                return hashAlgorithm.ComputeHash(Encoding.Default.GetBytes(input));
            }
            finally
            {
                hashAlgorithm.Clear();
            }
        }
開發者ID:howbigbobo,項目名稱:DailyCode,代碼行數:22,代碼來源:MD5Hasher.cs

示例4: GenerateSHA1

        /// <summary>
        /// Generates a base64 encoded SHA1 hash from the input string.
        /// </summary>
        /// <param name="input">The input string to be hashed.</param>
        public static string GenerateSHA1(string input)
        {
            // extract password as unmanaged byte array
            SHA1Managed sha = new SHA1Managed();
            try
            {
                // generate hash using SHA1 provider
                byte[] passwordData = Encoding.UTF8.GetBytes(input);
                byte[] hashedPasswordData = sha.ComputeHash(passwordData);
                string hashedPassword = Convert.ToBase64String(
                    hashedPasswordData);

                // return hash
                return hashedPassword;
            }

            // ensure the hash is cleared from memory
            finally
            {
                sha.Clear();
            }
        }
開發者ID:nascentdigital,項目名稱:web-template,代碼行數:26,代碼來源:HashHelper.cs

示例5: SHAHash

        static byte[] SHAHash(byte[] input)
        {
            SHA1Managed sha = new SHA1Managed();

            byte[] output = sha.ComputeHash( input );

            sha.Clear();

            return output;
        }
開發者ID:nicolas-martin,項目名稱:csgoescrow,代碼行數:10,代碼來源:Bot.cs

示例6: SHA1Encrypt

        public string SHA1Encrypt(string strIN)
        {
            byte[] tmpByte;
            SHA1 sha1 = new SHA1Managed();

            tmpByte = sha1.ComputeHash(System.Text.Encoding.ASCII.GetBytes(strIN));
            string strResult = BitConverter.ToString(tmpByte);
            strResult = strResult.Replace("-", "");
            sha1.Clear();
            sha1 = null;
            return strResult;
        }
開發者ID:jeanmahai,項目名稱:PublicTools,代碼行數:12,代碼來源:HashEncrypt.cs

示例7: UpdateTmdContents

        /// <summary>
        /// Updates the Content Info in the Tmd.
        /// Tmd and Contents must be in the same Directory
        /// </summary>
        /// <param name="tmdfile"></param>
        public static void UpdateTmdContents(string tmdfile)
        {
            FileStream tmd = new FileStream(tmdfile, FileMode.Open, FileAccess.ReadWrite);

            tmd.Seek(0x1de, SeekOrigin.Begin);
            int contentcount = Tools.HexStringToInt(tmd.ReadByte().ToString("x2") + tmd.ReadByte().ToString("x2"));

            for (int i = 0; i < contentcount; i++)
            {
                int oldsize = 0;
                int contentpos = 0x1e4 + (36 * i);

                tmd.Seek(contentpos, SeekOrigin.Begin);
                string id = tmd.ReadByte().ToString("x2") + tmd.ReadByte().ToString("x2") + tmd.ReadByte().ToString("x2") + tmd.ReadByte().ToString("x2");
                string index = "0000" + tmd.ReadByte().ToString("x2") + tmd.ReadByte().ToString("x2");
                string type = tmd.ReadByte().ToString("x2") + tmd.ReadByte().ToString("x2");

                if (type != "0001") continue;

                try
                {
                    oldsize = Tools.HexStringToInt(tmd.ReadByte().ToString("x2") +
                        tmd.ReadByte().ToString("x2") +
                        tmd.ReadByte().ToString("x2") +
                        tmd.ReadByte().ToString("x2") +
                        tmd.ReadByte().ToString("x2") +
                        tmd.ReadByte().ToString("x2") +
                        tmd.ReadByte().ToString("x2") +
                        tmd.ReadByte().ToString("x2"));
                }
                catch { }

                byte[] oldsha1 = new byte[20];
                tmd.Read(oldsha1, 0, oldsha1.Length);
                string fileName = id;

                if (!File.Exists(tmdfile.Remove(tmdfile.LastIndexOf('/') + 1) + fileName + ".app"))
                    fileName = index;

                if (File.Exists(tmdfile.Remove(tmdfile.LastIndexOf('/') + 1) + fileName + ".app"))
                {
                    byte[] content = Wii.Tools.LoadFileToByteArray(tmdfile.Remove(tmdfile.LastIndexOf('/') + 1) + fileName + ".app");
                    int newsize = content.Length;

                    if (newsize != oldsize)
                    {
                        byte[] changedsize = Tools.FileLengthToByteArray(newsize);

                        tmd.Seek(contentpos + 8, SeekOrigin.Begin);
                        for (int x = 8; x > changedsize.Length; x--) tmd.WriteByte(0x00);
                        tmd.Write(changedsize, 0, changedsize.Length);
                    }

                    SHA1Managed sha1 = new SHA1Managed();
                    byte[] newsha1 = sha1.ComputeHash(content);
                    sha1.Clear();

                    if (Tools.CompareByteArrays(newsha1, oldsha1) == false)
                    {
                        tmd.Seek(contentpos + 16, SeekOrigin.Begin);
                        tmd.Write(newsha1, 0, newsha1.Length);
                    }
                }
                else
                {
                    throw new Exception("At least one content file wasn't found!");
                }
            }

            tmd.Close();
        }
開發者ID:Plombo,項目名稱:showmiiwads,代碼行數:76,代碼來源:Wii.cs


注:本文中的System.Security.Cryptography.SHA1Managed.Clear方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。