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


C# System.Security.Cryptography.SHA1CryptoServiceProvider.Dispose方法代码示例

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


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

示例1: Generate

        public static string Generate()
        {
            // Generate random
            var rnd = new System.Security.Cryptography.RNGCryptoServiceProvider();
            var entropy = new byte[bytes - 4];
            try {
                rnd.GetBytes(entropy);
            } finally {
                rnd.Dispose();
            }

            // Hash
            var sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            byte[] hash;
            try {
                hash = sha.ComputeHash(entropy);
            } finally {
                sha.Dispose();
            }

            // Compute output
            var raw = new byte[bytes];
            Array.Copy(entropy, 0, raw, 0, bytes - 4);
            Array.Copy(hash, 0, raw, bytes - 4, 4);

            // Convert to Base64
            return Convert.ToBase64String(raw).Replace('+', '!').Replace('/', '~');
        }
开发者ID:invertedtomato,项目名称:Amos2,代码行数:28,代码来源:Tokens.cs

示例2: Validate

        public static bool Validate(string sid)
        {
            // Basic sanity checks
            if (null == sid) return false;
            if (sid.Length != 32) return false;

            // Decode Base64
            byte[] raw;
            try {
                raw = Convert.FromBase64String(sid.Replace('!', '+').Replace('~', '/'));
            } catch (FormatException) {
                return false; // Not valid Base64
            }

            // Break into components
            var entropy = new byte[bytes - 4];
            var hash = new byte[4];
            Array.Copy(raw, 0, entropy, 0, bytes - 4);
            Array.Copy(raw, bytes - 4, hash, 0, 4);

            // Hash
            var sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            byte[] buffer;
            try {
                buffer = sha.ComputeHash(entropy);
            } finally {
                sha.Dispose();
            }
            var checkhash = new byte[4];
            Array.Copy(buffer, 0, checkhash, 0, 4);

            // Check hash
            if (!hash.ByteArraysEqual(checkhash)) return false;

            return true;
        }
开发者ID:invertedtomato,项目名称:Amos2,代码行数:36,代码来源:Tokens.cs

示例3: Main

        public static string root = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // string root points to MyDocuments

        #endregion Fields

        #region Methods

        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                if (args[0] == "-v")
                {
                    Console.WriteLine("asdasd");
                    if (File.Exists(prefs + "/gkey"))
                    {
                            using (System.IO.StreamReader sr = new System.IO.StreamReader(prefs + "/gkey"))
                            {
                                string data = sr.ReadToEnd();
                                string[] f = data.Split('\n');
                                sr.Dispose();
                                if (f[0] == "accepted")
                                {
                                    string HASH = f[1].ToString();
                                    using (System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider())
                                    {
                                        string hashsum = string.Empty;                  // Empty storage allocator
                                        byte[] da = sha1.ComputeHash(Encoding.Unicode.GetBytes(prefs + "/gkey"));       // byte array
                                        foreach (byte by in data)
                                        {
                                            hashsum += String.Format("{0,2:X2}", by);        // :-)
                                        }

                                        if (hashsum.ToString() != HASH.ToString())
                                        {
                                            Console.ForegroundColor = ConsoleColor.Red;
                                            Console.Write("SECURITY COMPROMISED!\n\nSHA1 HASH MODIFIED!\nRECORD DOES NOT MATCH G_KEY!\n\nCACHE WILL BE DELETED FOR SECURITY.");
                                            Console.Read();

                                        }

                                        else ;
                                        sha1.Dispose();

                                        try
                                        {
                                            Directory.Delete(prefs);
                                        }

                                        catch { ; }
                                    }
                                }

                            }

                    }
                }

            }

            else
            {
                Console.Write("This is not a standalone application.");
            }
        }
开发者ID:kryptonX,项目名称:Scale,代码行数:64,代码来源:Program.cs


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