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


C# HMAC.Initialize方法代码示例

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


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

示例1: Compute_PHash

        static byte[] Compute_PHash(int bytes, byte[][] seeds, HMAC hmac, int blockSize)
        {
            int blocks = (bytes / blockSize) + (bytes % blockSize == 0 ? 0 : 1);
            byte[] ret = new byte[blockSize * blocks];
            byte[] prev = null;

            for (int i = 0; i < blocks; i++) {
                hmac.Initialize ();
                if (prev == null) {
                    for (int q = 0; q < seeds.Length; q ++)
                        hmac.TransformBlock (seeds[q], 0, seeds[q].Length, seeds[q], 0);
                } else {
                    hmac.TransformBlock (prev, 0, prev.Length, prev, 0);
                }
                hmac.TransformFinalBlock (Utility.EmptyByteArray, 0, 0);
                prev = hmac.Hash;
                hmac.Initialize ();
                hmac.TransformBlock (prev, 0, prev.Length, prev, 0);
                for (int q = 0; q < seeds.Length; q++)
                    hmac.TransformBlock (seeds[q], 0, seeds[q].Length, seeds[q], 0);
                hmac.TransformFinalBlock (Utility.EmptyByteArray, 0, 0);
                for (int q = 0; q < blockSize; q++)
                    ret[i * blockSize + q] = hmac.Hash[q];
            }
            return ret;
        }
开发者ID:kazuki,项目名称:opencrypto-tls,代码行数:26,代码来源:MD5_AND_SHA1.cs

示例2: HKDF

		static readonly byte[] emptyArray64 = new byte[64]; // for SHA-512

		public HKDF(Func<HMAC> hmacFactory, byte[] ikm, byte[] salt = null, byte[] context = null)
		{
			hmac = hmacFactory();
			hmac2 = hmac as HMAC2;
			hashLength = hmac.HashSize >> 3;

			// a malicious implementation of HMAC could conceivably mess up the shared static empty byte arrays, which are still writeable...
			hmac.Key = salt ?? (hashLength == 48 ? emptyArray48 : hashLength == 64 ? emptyArray64 : hashLength == 32 ? emptyArray32 : hashLength == 20 ? emptyArray20 : new byte[hashLength]);

			// re-keying hmac with PRK
			hmac.TransformBlock(ikm, 0, ikm.Length, null, 0);
			hmac.TransformFinalBlock(ikm, 0, 0);
			hmac.Key = (hmac2 != null) ? hmac2.HashInner : hmac.Hash;
			hmac.Initialize();
			this.context = context;
			Reset();
		}
开发者ID:sdrapkin,项目名称:SecurityDriven.Inferno,代码行数:19,代码来源:HKDF.cs

示例3: computePin

        /// <summary>
        /// Generates PIN code based on given Base32 secret code, interval length, and desired PIN code length
        /// </summary>
        /// <param name="secret">Base32 Secret Code</param>
        /// <returns>PIN code with desired number of digits</returns>
        public string computePin(string secret)
        {
            string strToReturn = "";
                try
                {
                    byte[] keyBytes = FromBase32String(secret);
                    mac = new HMACSHA1(keyBytes);
                    mac.Initialize();
                    strToReturn = generateResponseCode(getCurrentInterval());
                }
                catch (Exception e)
                {
                    return e.Message;
                }

            return strToReturn;
        }
开发者ID:Anheledir,项目名称:authenticator-plus,代码行数:22,代码来源:CodeGenerator.cs

示例4: CheckE

		public void CheckE (string testName, HMAC algo, byte[] data, byte[] result)
		{
			byte[] copy = new byte[data.Length];
			for (int i = 0; i < data.Length - 1; i++)
				algo.TransformBlock (data, i, 1, copy, i);
			algo.TransformFinalBlock (data, data.Length - 1, 1);
			Compare (result, algo.Hash, testName + "e");
			algo.Initialize ();
		}
开发者ID:nlhepler,项目名称:mono,代码行数:9,代码来源:HMACSHA384Test.cs

示例5: CheckD

		public void CheckD (string testName, HMAC algo, byte[] data, byte[] result)
		{
			algo.TransformFinalBlock (data, 0, data.Length);
			Compare (result, algo.Hash, testName + "d");
			algo.Initialize ();
		}
开发者ID:nlhepler,项目名称:mono,代码行数:6,代码来源:HMACSHA384Test.cs

示例6: CamoSignature

 public CamoSignature(HMAC hmac)
 {
     _hmac = hmac;
     _hmac.Initialize();
 }
开发者ID:maartenba,项目名称:CamoDotNet,代码行数:5,代码来源:CamoSignature.cs


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