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


C# HashAlgorithm.Clear方法代码示例

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


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

示例1: HashText

 private static string HashText(string text, string salt, HashAlgorithm hasher)
 {
     var hashedText = Convert.ToBase64String(
         hasher.ComputeHash(
             Encoding.UTF8.GetBytes(string.Concat(text, salt))
             )
         );
     hasher.Clear();
     return hashedText;
 }
开发者ID:mdayal,项目名称:WNG2,代码行数:10,代码来源:PasswordSecurityService.cs

示例2: Crypt

        byte[] Crypt(byte[] key, byte[] salt, byte[] prefix, HashAlgorithm A)
        {
            byte[] H = null, I = null;

            try
            {
                A.Initialize();
                AddToDigest(A, key);
                AddToDigest(A, salt);
                AddToDigest(A, key);
                FinishDigest(A);

                I = (byte[])A.Hash.Clone();

                A.Initialize();
                AddToDigest(A, key);
                AddToDigest(A, prefix);
                AddToDigest(A, salt);

                AddToDigestRolling(A, I, 0, I.Length, key.Length);

                int length = key.Length;
                for (int i = 0; i < 31 && length != 0; i++)
                {
                    AddToDigest(A, new[] { (length & (1 << i)) != 0 ? (byte)0 : key[0] });
                    length &= ~(1 << i);
                }
                FinishDigest(A);

                H = (byte[])A.Hash.Clone();

                for (int i = 0; i < 1000; i++)
                {
                    A.Initialize();
                    if ((i & 1) != 0) { AddToDigest(A, key); }
                    if ((i & 1) == 0) { AddToDigest(A, H); }
                    if ((i % 3) != 0) { AddToDigest(A, salt); }
                    if ((i % 7) != 0) { AddToDigest(A, key); }
                    if ((i & 1) != 0) { AddToDigest(A, H); }
                    if ((i & 1) == 0) { AddToDigest(A, key); }
                    FinishDigest(A);

                    Array.Copy(A.Hash, H, H.Length);
                }

                byte[] crypt = new byte[H.Length];
                int[] permutation = new[] { 11, 4, 10, 5, 3, 9, 15, 2, 8, 14, 1, 7, 13, 0, 6, 12 };
                Array.Reverse(permutation);
                for (int i = 0; i < crypt.Length; i++)
                {
                    crypt[i] = H[permutation[i]];
                }

                return crypt;
            }
            finally
            {
                A.Clear();
                Security.Clear(H);
                Security.Clear(I);
            }
        }
开发者ID:z0rg1nc,项目名称:CryptSharpFork,代码行数:62,代码来源:MD5Crypter.cs

示例3: DisposeAlgorithm

 /// <summary>
 /// Disposes hashing algorithm.
 /// </summary>
 /// <param name="hashAlgorithm">The hash algorithm to dispose.</param>
 private static void DisposeAlgorithm(HashAlgorithm hashAlgorithm)
 {
     hashAlgorithm.Clear();
 }
开发者ID:shahboura,项目名称:Hasher,代码行数:8,代码来源:StringHasher.cs

示例4: ComputeHash

 /// <summary> Mechanisms inherit from the HashAlgorithm base class so we can use that to cast the crypto service provider
 /// </summary>
 /// <param name="provider">Type of provider</param>
 /// <param name="plainText">To be hash content</param>
 /// <returns>Array of bytes</returns>
 private byte[] ComputeHash(HashAlgorithm provider, string plainText)
 {
     //All hashing mechanisms inherit from the HashAlgorithm base class so we can use that to cast the crypto service provider
     byte[] hash = provider.ComputeHash(System.Text.Encoding.UTF8.GetBytes(plainText));
     provider.Clear();
     return hash;
 }
开发者ID:sidneylimafilho,项目名称:InfoControl,代码行数:12,代码来源:Cypher.cs

示例5: UnsaltedCrypt

        static string UnsaltedCrypt(HashAlgorithm algorithm, byte[] password)
        {
            try
            {
                algorithm.Initialize();
                algorithm.TransformBlock(password, 0, password.Length, password, 0);
                algorithm.TransformFinalBlock(new byte[0], 0, 0);

                string crypt = Convert.ToBase64String(algorithm.Hash);
                return crypt;
            }
            finally
            {
                algorithm.Clear();
            }
        }
开发者ID:z0rg1nc,项目名称:CryptSharpFork,代码行数:16,代码来源:LdapCrypter.cs

示例6: SaltedCrypt

        static string SaltedCrypt(HashAlgorithm algorithm, byte[] password, byte[] salt)
        {
            // If we're under the hash length, assume we only have the salt.
            int hashLength = algorithm.HashSize / 8;
            int saltOffset = salt.Length < hashLength ? 0 : hashLength;
            int saltLength = salt.Length - saltOffset;

            byte[] saltedHash = new byte[hashLength + saltLength];
            try
            {
                algorithm.Initialize();
                algorithm.TransformBlock(password, 0, password.Length, password, 0);
                algorithm.TransformBlock(salt, saltOffset, saltLength, salt, saltOffset);
                algorithm.TransformFinalBlock(new byte[0], 0, 0);

                Array.Copy(algorithm.Hash, saltedHash, hashLength);
                Array.Copy(salt, saltOffset, saltedHash, hashLength, saltLength);
                string crypt = Convert.ToBase64String(saltedHash);
                return crypt;
            }
            finally
            {
                algorithm.Clear();
                Security.Clear(saltedHash);
            }
        }
开发者ID:z0rg1nc,项目名称:CryptSharpFork,代码行数:26,代码来源:LdapCrypter.cs

示例7: Crypt

        byte[] Crypt(byte[] key, byte[] salt, int rounds, HashAlgorithm A)
        {
            byte[] P = null, S = null, H = null, I = null;

            try
            {
                A.Initialize();
                AddToDigest(A, key);
                AddToDigest(A, salt);
                AddToDigest(A, key);
                FinishDigest(A);

                I = (byte[])A.Hash.Clone();

                A.Initialize();
                AddToDigest(A, key);
                AddToDigest(A, salt);

                AddToDigestRolling(A, I, 0, I.Length, key.Length);

                int length = key.Length;
                for (int i = 0; i < 31 && length != 0; i++)
                {
                    AddToDigest(A, (length & (1 << i)) != 0 ? I : key);
                    length &= ~(1 << i);
                }
                FinishDigest(A);

                H = (byte[])A.Hash.Clone();

                A.Initialize();
                for (int i = 0; i < key.Length; i++)
                {
                    AddToDigest(A, key);
                }
                FinishDigest(A);

                P = new byte[key.Length];
                CopyRolling(A.Hash, 0, A.Hash.Length, P);

                A.Initialize();
                for (int i = 0; i < 16 + H[0]; i++)
                {
                    AddToDigest(A, salt);
                }
                FinishDigest(A);

                S = new byte[salt.Length];
                CopyRolling(A.Hash, 0, A.Hash.Length, S);

                for (int i = 0; i < rounds; i++)
                {
                    A.Initialize();
                    if ((i & 1) != 0) { AddToDigest(A, P); }
                    if ((i & 1) == 0) { AddToDigest(A, H); }
                    if ((i % 3) != 0) { AddToDigest(A, S); }
                    if ((i % 7) != 0) { AddToDigest(A, P); }
                    if ((i & 1) != 0) { AddToDigest(A, H); }
                    if ((i & 1) == 0) { AddToDigest(A, P); }
                    FinishDigest(A);

                    Array.Copy(A.Hash, H, H.Length);
                }

                byte[] crypt = new byte[H.Length];
                int[] permutation = GetCryptPermutation();
                for (int i = 0; i < crypt.Length; i++)
                {
                    crypt[i] = H[permutation[i]];
                }

                return crypt;
            }
            finally
            {
                A.Clear();
                Security.Clear(P);
                Security.Clear(S);
                Security.Clear(H);
                Security.Clear(I);
            }
        }
开发者ID:z0rg1nc,项目名称:CryptSharpFork,代码行数:82,代码来源:ShaCrypter.cs

示例8: Crypt

        byte[] Crypt(byte[] key, byte[] salt, int rounds, HashAlgorithm A)
        {
            byte[] H = null;

            try
            {
                A.Initialize();
                AddToDigest(A, salt);
                AddToDigest(A, key);
                FinishDigest(A);

                H = (byte[])A.Hash.Clone();

                for (int i = 0; i < (1 << rounds); i++)
                {
                    A.Initialize();
                    AddToDigest(A, H);
                    AddToDigest(A, key);
                    FinishDigest(A);

                    Array.Copy(A.Hash, H, H.Length);
                }

                return (byte[])H.Clone();
            }
            finally
            {
                A.Clear();
                Security.Clear(H);
            }
        }
开发者ID:z0rg1nc,项目名称:CryptSharpFork,代码行数:31,代码来源:PhpassCrypter.cs


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