本文整理汇总了C#中System.Security.Cryptography.HMAC.TransformBlock方法的典型用法代码示例。如果您正苦于以下问题:C# HMAC.TransformBlock方法的具体用法?C# HMAC.TransformBlock怎么用?C# HMAC.TransformBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.HMAC
的用法示例。
在下文中一共展示了HMAC.TransformBlock方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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();
}
示例3: 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 ();
}