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


C# MD5CryptoServiceProvider.GetType方法代碼示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            //geração de hash com MD5
            StreamReader sr = new StreamReader("Arquivo.txt");

            String mensagem = sr.ReadToEnd();

            sr.Close();

            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

            byte[] bytes = Encoding.Default.GetBytes(mensagem);

            byte[] hash = md5.ComputeHash(bytes);

            Gravar(hash, md5.GetType().Name);

            Process.Start("notepad", String.Format("{0}.hash", md5.GetType().Name));
        }
開發者ID:50minutos,項目名稱:VS2010,代碼行數:19,代碼來源:Program.cs

示例2: GenerateChecksum

        /// <summary>
        /// Generate a checksum.
        /// </summary>
        /// <param name="fullPath">The full path of the file to generate a checksum for.</param>
        public void GenerateChecksum(string fullPath)
        {
            using (FileStream file = new FileStream(fullPath, FileMode.Open,FileAccess.Read,FileShare.Read))
            {
                MD5 md5 = new MD5CryptoServiceProvider();
                byte[] retVal = md5.ComputeHash(file);
                file.Close();

                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < retVal.Length; i++)
                {
                    sb.Append(retVal[i].ToString("x2"));
                }

                Checksum = sb.ToString();
                ChecksumType = md5.GetType().ToString();
            }
        }
開發者ID:emmandeb,項目名稱:ClearCanvas-1,代碼行數:22,代碼來源:ManifestFile.cs

示例3: VerifyChecksum

        /// <summary>
        /// Verify a checksum.
        /// </summary>
        /// <param name="fullPath">The path to the file.</param>
        public void VerifyChecksum(string fullPath)
        {
            MD5 md5 = new MD5CryptoServiceProvider();
            if (md5.GetType().ToString().Equals(ChecksumType))
            {
                using (FileStream file = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {

                    byte[] retVal = md5.ComputeHash(file);
                    file.Close();

                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < retVal.Length; i++)
                    {
                        sb.Append(retVal[i].ToString("x2"));
                    }

                    if (!Checksum.Equals(sb.ToString()))
                        throw new ApplicationException("Checksum does not match for file " + fullPath);
                }
            }
            else
            {
                throw new ApplicationException("Unknown checksum type: " + ChecksumType);
            }
        }
開發者ID:emmandeb,項目名稱:ClearCanvas-1,代碼行數:30,代碼來源:ManifestFile.cs


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