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


C# HashAlgorithm.Initialize方法代码示例

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


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

示例1: StartTests

 protected int StartTests(HashAlgorithm hash, byte[] input, byte[] result)
 {
     try {
         byte[] ch = hash.ComputeHash(input, 0, input.Length);
         if (!ArrayEquals(ch, result))
             AddError("HB-ST1");
     } catch {
         AddError("HB-ST2");
     }
     try {
         // feed input byte-by-byte
         for(int i = 0; i < input.Length - 1; i++) {
             hash.TransformBlock(input, i, 1, input, i);
         }
         if (input.Length > 0)
             hash.TransformFinalBlock(input, input.Length - 1, 1);
         else
             hash.TransformFinalBlock(input, 0, 0);
         if (!ArrayEquals(hash.Hash, result)) {
             AddError("HB-ST3");
             Console.WriteLine(Encoding.ASCII.GetString(input));
         }
     } catch {
         AddError("HB-ST4");
     } finally {
         hash.Initialize();
     }
     return 4;
 }
开发者ID:maikgreubel,项目名称:securitylibrary,代码行数:29,代码来源:HashBox.cs

示例2: FIPS186_b

 public void FIPS186_b(string testName, HashAlgorithm hash, byte[] input, byte[] result)
 {
     byte[] output = hash.ComputeHash (input, 0, input.Length);
     Assert.AreEqual (result, output, testName + ".b.1");
     Assert.AreEqual (result, hash.Hash, testName + ".b.2");
     // required or next operation will still return old hash
     hash.Initialize ();
 }
开发者ID:amatai,项目名称:crimson,代码行数:8,代码来源:SHA1Test.cs

示例3: GetDigestedBytes

 internal byte[] GetDigestedBytes(HashAlgorithm hash)
 {
     this.m_c14nDoc.WriteHash(hash, DocPosition.BeforeRootElement, this.m_ancMgr);
     hash.TransformFinalBlock(new byte[0], 0, 0);
     byte[] buffer = (byte[]) hash.Hash.Clone();
     hash.Initialize();
     return buffer;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:ExcCanonicalXml.cs

示例4: FIPS186_c

 public void FIPS186_c(string testName, HashAlgorithm hash, byte[] input, byte[] result)
 {
     MemoryStream ms = new MemoryStream (input);
     byte[] output = hash.ComputeHash (ms);
     Assert.AreEqual (result, output, testName + ".c.1");
     Assert.AreEqual (result, hash.Hash, testName + ".c.2");
     // required or next operation will still return old hash
     hash.Initialize ();
 }
开发者ID:amatai,项目名称:crimson,代码行数:9,代码来源:SHA1Test.cs

示例5: FIPS186_d

 public void FIPS186_d(string testName, HashAlgorithm hash, byte[] input, byte[] result)
 {
     hash.TransformFinalBlock (input, 0, input.Length);
     // LAMESPEC or FIXME: TransformFinalBlock doesn't return HashValue !
     // AssertEquals( testName + ".d.1", result, output );
     Assert.AreEqual (result, hash.Hash, testName + ".d");
     // required or next operation will still return old hash
     hash.Initialize ();
 }
开发者ID:amatai,项目名称:crimson,代码行数:9,代码来源:SHA1Test.cs

示例6: ComputeSha1Hash

		/// <summary>
		/// Computes the Sha1 hash value for the specified byte array.
		/// </summary>
		/// <param name="input">The byte-array to compute the hash value for.</param>
		/// <returns>The computed hash value.</returns>
		public static byte[] ComputeSha1Hash(byte[] input)
		{
			byte[] hash = null;
			using (HashAlgorithm sha1 = new HashAlgorithm(HashAlgorithmType.SHA1))
			{
				sha1.Initialize();
				hash = sha1.ComputeHash(input);
			}
			return hash;
		}
开发者ID:Injac,项目名称:SocketIO.NetMF,代码行数:15,代码来源:CryptoUtils.cs

示例7: Checksum

 /// <summary>
 /// Initialize a new checksum object.
 /// </summary>
 /// <param name="alg">The checksumming algorithm to use.</param>
 public Checksum(Algorithm alg)
 {
     switch (alg)
     {
         case Algorithm.SHA0:
             hash = new SHA0();
             break;
         case Algorithm.SHA1:
             hash = HashAlgorithm.Create("SHA1");
             break;
         case Algorithm.MD5:
             hash = HashAlgorithm.Create("MD5");
             break;
     }
     hash.Initialize();
     this.alg = alg;
 }
开发者ID:serefbingol,项目名称:atmos-dotnet,代码行数:21,代码来源:Checksum.cs

示例8: TestComputeHash

        public static bool TestComputeHash(HashAlgorithm hash, byte[] data, byte[] digest)
        {
            hash.Initialize();

            if (!CompareBytes(hash.ComputeHash(data), digest))
            {
                Log.Comment("ComputeHash test failed");
                return false;
            }

            return true;
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:12,代码来源:SHAVS.cs

示例9: MyRSA

 public MyRSA()
 {
     m_hasher = MySHA256.Create();
     m_hasher.Initialize();
 }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:5,代码来源:MyRSA.cs

示例10: TestHash

        // tests a hash algorithm instance 
        public static bool TestHash(HashAlgorithm hash)
        {
            bool bRes = true;
            // decide on the number of passes
            int nPasses = m_Rnd.Next(MAX_PASSES) + 1;
            Log.Comment("Doing " + nPasses + " passes...");

            while (0 != nPasses--)
            {
                // init the hash object
                hash.Initialize();

                // create a random data blob
                int nSize = m_Rnd.Next(MAX_SIZE);
                byte[] abBlob = new byte[nSize];
                Log.Comment("Test buffer size is " + nSize);

                // first try ComputeHash
                byte[] hash1 = hash.ComputeHash(abBlob);

                //			Log.Comment("Hash1:");
                //			PrintByteArray(hash1);

                // now try stream
                hash.Initialize();

                byte[] hash2 = hash.TransformFinalBlock(abBlob, 0, abBlob.Length);

                //CryptoStream cs = new CryptoStream(CryptoStream.Null, hash, CryptoStreamMode.Write);
                //cs.Write(abBlob, 0, abBlob.Length);
                //cs.Close();
                //byte[] hash2 = hash.Hash;

                //			Log.Comment("Hash2:");
                //			PrintByteArray(hash2);

                if (Compare(hash1, hash2))
                {
                    Log.Comment(" OK.");
                }
                else
                {
                    bRes = false;
                    Log.Comment(" FAILED. Hashes are different.");
                }

            }
            return bRes;
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:50,代码来源:GetHashvsStream.cs

示例11: CompareHashes

        public static bool CompareHashes(HashAlgorithm algorithm1, HashAlgorithm algorithm2, byte[] data)
        {
            algorithm1.Initialize();
            algorithm2.Initialize();

            byte[] hash1 = algorithm1.ComputeHash(data);
            byte[] hash2 = algorithm2.ComputeHash(data);

            if (!CompareBytes(hash1, hash2))
            {
                Log.Comment("ERROR - HASH VALUE MISCOMPARISON!\n");
                Log.Comment("Algorithm 1 : " + algorithm1.ToString());
                Log.Comment("Algorithm 2 : " + algorithm2.ToString());
                Log.Comment("Data: " + ByteArrayToString(data));
                return false;
            }

            return true;
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:19,代码来源:HashCompare.cs

示例12: GenerateHash

	// Generate the hash value for this assembly using a given algorith.
	public byte[] GenerateHash(HashAlgorithm hashAlg)
			{
				if(hashAlg == null)
				{
					throw new ArgumentNullException("hashAlg");
				}
				byte[] rawData = RawData;
				if(rawData == null)
				{
					return null;
				}
				hashAlg.Initialize();
				return hashAlg.ComputeHash(rawData);
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:15,代码来源:Hash.cs

示例13: 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

示例14: Hashing

 public Hashing(HashAlgorithm hashAlgorithm)
 {
     _hashAlgorithm = hashAlgorithm;
     _hashAlgorithm.Initialize();
 }
开发者ID:rubenlr,项目名称:Utilities,代码行数:5,代码来源:Hashing.cs

示例15: FIPS186_e

 public void FIPS186_e(string testName, HashAlgorithm hash, byte[] input, byte[] result)
 {
     byte[] copy = new byte [input.Length];
     for (int i=0; i < input.Length - 1; i++)
         hash.TransformBlock (input, i, 1, copy, i);
     hash.TransformFinalBlock (input, input.Length - 1, 1);
     // LAMESPEC or FIXME: TransformFinalBlock doesn't return HashValue !
     // AssertEquals (testName + ".e.1", result, output);
     Assert.AreEqual (result, hash.Hash, testName + ".e");
     // required or next operation will still return old hash
     hash.Initialize ();
 }
开发者ID:amatai,项目名称:crimson,代码行数:12,代码来源:SHA1Test.cs


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