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


C# IDigest.Update方法代码示例

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


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

示例1: Init

        public void Init(ICipherParameters parameters)
        {
            // setup AAD
            var aadParam = parameters as AADParameter;
            SecurityAssert.NotNull(aadParam);

            var a = aadParam.AAD;
            aSize = a.Length * 8;

            // setup IV
            var ivParam = aadParam.Parameters as IVParameter;
            SecurityAssert.NotNull(ivParam);

            var iv = ivParam.IV;
            ivSize = iv.Length * 8;

            // setup cipher
            Cipher.Init(ivParam.Parameters);

            // setup H subkey
            h = new byte[16];
            Cipher.EncryptBlock(new byte[16], 0, h, 0);

            // setup tag hash
            tagHash = new GHash(h);
            tagHash.Update(a, 0, a.Length);
            var tagAADPaddingLength = 16 - a.Length % 16;
            tagHash.Update(new byte[tagAADPaddingLength], 0, tagAADPaddingLength);

            // setup pre-counter block
            if (iv.Length == 12)
            {
                // IV || 0^31 ||1

                j0 = new byte[16];
                Array.Copy(iv, j0, 12);
                j0[15] = 1;
            }
            else
            {
                // GHASH_H(IV || 0^(s+64) || [len(IV)])

                var j0PaddingLength = 8 + (16 - iv.Length % 16) % 16;

                var j0Hash = new GHash(h);
                j0Hash.Update(iv, 0, iv.Length);
                j0Hash.Update(new byte[j0PaddingLength], 0, j0PaddingLength);
                j0Hash.Update(EndianBitConverter.Big.GetBytes(ivSize), 0, sizeof(long));

                j0 = j0Hash.Digest();
            }

            ctr = new CTRBlockCipher(Cipher);
            ctr.Init(new IVParameter(null, j0));
            ctr.Inc();

            cSize = 0;
        }
开发者ID:will14smith,项目名称:Crypto,代码行数:58,代码来源:GCMCipher.cs

示例2: HashDF

	    /**
	     * Used by both Dual EC and Hash.
	     */
	    internal static byte[] HashDF(IDigest digest, byte[] seedMaterial, int seedLength)
	    {
	         // 1. temp = the Null string.
	        // 2. .
	        // 3. counter = an 8-bit binary value representing the integer "1".
	        // 4. For i = 1 to len do
	        // Comment : In step 4.1, no_of_bits_to_return
	        // is used as a 32-bit string.
	        // 4.1 temp = temp || Hash (counter || no_of_bits_to_return ||
	        // input_string).
	        // 4.2 counter = counter + 1.
	        // 5. requested_bits = Leftmost (no_of_bits_to_return) of temp.
	        // 6. Return SUCCESS and requested_bits.
	        byte[] temp = new byte[(seedLength + 7) / 8];

	        int len = temp.Length / digest.GetDigestSize();
	        int counter = 1;

	        byte[] dig = new byte[digest.GetDigestSize()];

	        for (int i = 0; i <= len; i++)
	        {
	            digest.Update((byte)counter);

	            digest.Update((byte)(seedLength >> 24));
	            digest.Update((byte)(seedLength >> 16));
	            digest.Update((byte)(seedLength >> 8));
	            digest.Update((byte)seedLength);

	            digest.BlockUpdate(seedMaterial, 0, seedMaterial.Length);

	            digest.DoFinal(dig, 0);

	            int bytesToCopy = ((temp.Length - i * dig.Length) > dig.Length)
	                    ? dig.Length
	                    : (temp.Length - i * dig.Length);
	            Array.Copy(dig, 0, temp, i * dig.Length, bytesToCopy);

	            counter++;
	        }

	        // do a left shift to get rid of excess bits.
	        if (seedLength % 8 != 0)
	        {
	            int shift = 8 - (seedLength % 8);
	            uint carry = 0;

                for (int i = 0; i != temp.Length; i++)
	            {
	                uint b = temp[i];
	                temp[i] = (byte)((b >> shift) | (carry << (8 - shift)));
	                carry = b;
	            }
	        }

            return temp;
	    }
开发者ID:KimikoMuffin,项目名称:bc-csharp,代码行数:60,代码来源:DrbgUtilities.cs

示例3: MakeTestHash

		private byte[] MakeTestHash(
			IDigest digest)
		{
			for (int i = 0; i < digest.GetDigestSize(); ++i)
			{
				digest.Update((byte) i);
			}

			digest.BlockUpdate(TestBytes, 0, TestBytes.Length);

			return DigestUtilities.DoFinal(digest);
		}
开发者ID:KimikoMuffin,项目名称:bc-csharp,代码行数:12,代码来源:TestDigestUtil.cs

示例4: CalculateX

 public static BigInteger CalculateX(IDigest digest, BigInteger N, byte[] salt, byte[] identity, byte[] password)
 {
     byte[] output = new byte[digest.GetDigestSize()];
     digest.BlockUpdate(identity, 0, identity.Length);
     digest.Update(0x3a);
     digest.BlockUpdate(password, 0, password.Length);
     digest.DoFinal(output, 0);
     digest.BlockUpdate(salt, 0, salt.Length);
     digest.BlockUpdate(output, 0, output.Length);
     digest.DoFinal(output, 0);
     return new BigInteger(1, output).Mod(N);
 }
开发者ID:Novo,项目名称:apbprivateserver,代码行数:12,代码来源:Srp6Utilities.cs

示例5: EMSA_PKCS1_v1_5_Encode

        private static byte[] EMSA_PKCS1_v1_5_Encode(byte[] input, int emLen, IDigest hash)
        {
            hash.Update(input, 0, input.Length);
            var h = hash.Digest();

            byte[] t;
            using (var mem = new MemoryStream())
            {
                var derWriter = new DERWriter(mem);

                derWriter.Write(new ASN1Sequence(new ASN1Object[]
                {
                    new ASN1Sequence(new ASN1Object[] {
                        hash.Id,
                        new ASN1Null()
                    }),
                    new ASN1OctetString(h)
                }));

                t = mem.ToArray();
            }

            SecurityAssert.SAssert(emLen >= t.Length + 11);

            var ps = new byte[emLen - t.Length - 3];
            SecurityAssert.SAssert(ps.Length >= 8);
            for (var i = 0; i < ps.Length; i++) { ps[i] = 0xff; }

            var em = new byte[emLen];
            em[0] = 0;
            em[1] = 1;
            Array.Copy(ps, 0, em, 2, ps.Length);
            em[ps.Length + 2] = 0;
            Array.Copy(t, 0, em, ps.Length + 3, t.Length);

            return em;
        }
开发者ID:will14smith,项目名称:Crypto,代码行数:37,代码来源:RSA.cs

示例6: TestDigest

        private void TestDigest(IDigest digest, string[] expected)
        {
            byte[] hash = new byte[digest.GetDigestSize()];

            for (int i = 0; i != messages.Length; i++)
            {
                if (messages.Length != 0)
                {
                    byte[] data = Hex.Decode(messages[i]);

                    digest.BlockUpdate(data, 0, data.Length);
                }

                digest.DoFinal(hash, 0);

                if (!Arrays.AreEqual(Hex.Decode(expected[i]), hash))
                {
                    Fail("sha3 mismatch on " + digest.AlgorithmName + " index " + i);
                }
            }

            byte[] k64 = new byte[1024 * 64];

            for (int i = 0; i != k64.Length; i++)
            {
                k64[i] = (byte)'a';
            }

            digest.BlockUpdate(k64, 0, k64.Length);

            digest.DoFinal(hash, 0);

            if (!Arrays.AreEqual(Hex.Decode(expected[messages.Length]), hash))
            {
                Fail("sha3 mismatch on " + digest.AlgorithmName + " 64k a");
            }

            for (int i = 0; i != k64.Length; i++)
            {
                digest.Update((byte)'a');
            }

            digest.DoFinal(hash, 0);

            if (!Arrays.AreEqual(Hex.Decode(expected[messages.Length]), hash))
            {
                Fail("sha3 mismatch on " + digest.AlgorithmName + " 64k a single");
            }


            for (int i = 0; i != k64.Length; i++)
            {
                k64[i] = (byte)('a' + (i % 26));
            }

            digest.BlockUpdate(k64, 0, k64.Length);

            digest.DoFinal(hash, 0);

            if (!Arrays.AreEqual(Hex.Decode(expected[messages.Length + 1]), hash))
            {
                Fail("sha3 mismatch on " + digest.AlgorithmName + " 64k alpha");
            }

            for (int i = 0; i != 64; i++)
            {
                digest.Update(k64[i * 1024]);
                digest.BlockUpdate(k64, i * 1024 + 1, 1023);
            }

            digest.DoFinal(hash, 0);

            if (!Arrays.AreEqual(Hex.Decode(expected[messages.Length + 1]), hash))
            {
                Fail("sha3 mismatch on " + digest.AlgorithmName + " 64k chunked alpha");
            }

            TestDigestDoFinal(digest);

            //
            // extremely long data test
            //
            //Console.WriteLine("Starting very long");
            //for (int i = 0; i != 16384; i++)
            //{
            //    for (int j = 0; j != 1024; j++)
            //    {
            //        digest.BlockUpdate(xtremeData, 0, xtremeData.Length);
            //    }
            //}
    
            //digest.DoFinal(hash, 0);
    
            //if (!Arrays.AreEqual(Hex.Decode(expected[messages.Length + 2]), hash))
            //{
            //    Fail("sha3 mismatch on " + digest.AlgorithmName + " extreme data test");
            //}
            //Console.WriteLine("Done");
        }
开发者ID:andibadra,项目名称:bc-csharp,代码行数:99,代码来源:SHA3DigestTest.cs

示例7: DigestTest

        private void DigestTest(IDigest Digest, string[] Expected)
        {
            byte[] hash = new byte[Digest.DigestSize];

            for (int i = 0; i != _messages.Length; i++)
            {
                if (_messages.Length != 0)
                {
                    byte[] data = HexConverter.Decode(_messages[i]);
                    Digest.BlockUpdate(data, 0, data.Length);
                }

                Digest.DoFinal(hash, 0);

                if (Compare.AreEqual(HexConverter.Decode(Expected[i]), hash) == false)
                    throw new Exception("Keccak: Expected hash is not equal! Expected: " + Expected[i] + " Received: " + HexConverter.ToString(hash));
            }

            byte[] k64 = new byte[1024 * 64];

            for (int i = 0; i != k64.Length; i++)
                k64[i] = (byte)'a';

            Digest.BlockUpdate(k64, 0, k64.Length);
            Digest.DoFinal(hash, 0);

            if (Compare.AreEqual(HexConverter.Decode(Expected[_messages.Length]), hash) == false)
                throw new Exception("Keccak: Expected hash is not equal! Expected: " + Expected[_messages.Length] + " Received: " + HexConverter.ToString(hash));

            for (int i = 0; i != k64.Length; i++)
                Digest.Update((byte)'a');

            Digest.DoFinal(hash, 0);

            if (Compare.AreEqual(HexConverter.Decode(Expected[_messages.Length]), hash) == false)
                throw new Exception("Keccak: Expected hash is not equal! Expected: " + Expected[_messages.Length] + " Received: " + HexConverter.ToString(hash));

            for (int i = 0; i != k64.Length; i++)
                k64[i] = (byte)('a' + (i % 26));

            Digest.BlockUpdate(k64, 0, k64.Length);
            Digest.DoFinal(hash, 0);

            if (Compare.AreEqual(HexConverter.Decode(Expected[_messages.Length + 1]), hash) == false)
                throw new Exception("Keccak: Expected hash is not equal! Expected: " + Expected[_messages.Length + 1] + " Received: " + HexConverter.ToString(hash));

            for (int i = 0; i != 64; i++)
            {
                Digest.Update(k64[i * 1024]);
                Digest.BlockUpdate(k64, i * 1024 + 1, 1023);
            }

            Digest.DoFinal(hash, 0);

            if (Compare.AreEqual(HexConverter.Decode(Expected[_messages.Length + 1]), hash) == false)
                throw new Exception("Keccak: Expected hash is not equal! Expected: " + Expected[_messages.Length + 1] + " Received: " + HexConverter.ToString(hash));

            DoFinalTest(Digest);

            /*// very long test (passes)
            for (int i = 0; i != 16384; i++)
            {
                for (int j = 0; j != 1024; j++)
                    Digest.BlockUpdate(_xtremeData, 0, _xtremeData.Length);
            }

            Digest.DoFinal(hash, 0);

            if (Compare.AreEqual(HexConverter.Decode(Expected[_messages.Length + 2]), hash) == false)
                throw new Exception("Keccak: Expected hash is not equal! Expected: " + Expected[_messages.Length + 2] + " Received: " + hash);*/
        }
开发者ID:modulexcite,项目名称:CEX,代码行数:71,代码来源:KeccakTest.cs

示例8: UpdateDigestWithKDFParameters

        /// <summary>
        /// Generates the KDF parameters.
        /// Sess Sections 7 & 8 of RFC 6637 (http://tools.ietf.org/html/rfc6637) for more details
        /// </summary>
        /// <returns></returns>
        private void UpdateDigestWithKDFParameters(IDigest digest)
        {
            var agreement = new ECDHBasicAgreement();
            agreement.Init(_privateKey);
            var zb = agreement.CalculateAgreement(_publicKey).ToByteArrayUnsigned();

            digest.Update(0x00);
            digest.Update(0x00);
            digest.Update(0x00);
            digest.Update(0x01);

            digest.BlockUpdate(zb, 0, zb.Length);

            var oid = _publicKey.PublicKeyParamSet.ToBytes();
            digest.Update((byte)oid.Length);
            digest.BlockUpdate(oid, 0, oid.Length);
            digest.Update((byte)PublicKeyAlgorithmTag.Ecdh);
            digest.Update(0x3);
            digest.Update(0x1);
            digest.Update((byte)_publicKey.HashAlgorithm);
            digest.Update((byte)_publicKey.SymmetricKeyAlgorithm);

            digest.BlockUpdate(_anonymousSender, 0, _anonymousSender.Length);
            digest.BlockUpdate(_fingerPrint, 0, _fingerPrint.Length);
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:30,代码来源:RFC6637ECDHEngine.cs

示例9: ComputeMAC

        private byte[] ComputeMAC(IDigest macAlgo, long seqNum, RecordType type, TlsVersion version, byte[] content)
        {
            macAlgo.Update(EndianBitConverter.Big.GetBytes(seqNum), 0, sizeof(long));
            macAlgo.Update(new[] { (byte)type, version.Major, version.Major }, 0, 3);
            macAlgo.Update(EndianBitConverter.Big.GetBytes((ushort)content.Length), 0, sizeof(ushort));
            macAlgo.Update(content, 0, content.Length);

            return macAlgo.Digest();
        }
开发者ID:will14smith,项目名称:Crypto,代码行数:9,代码来源:BlockCipherStrategy.cs


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