本文整理汇总了C#中IDigest.BlockUpdate方法的典型用法代码示例。如果您正苦于以下问题:C# IDigest.BlockUpdate方法的具体用法?C# IDigest.BlockUpdate怎么用?C# IDigest.BlockUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDigest
的用法示例。
在下文中一共展示了IDigest.BlockUpdate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HashPaddedPair
private static BigInteger HashPaddedPair(IDigest digest, BigInteger N, BigInteger n1, BigInteger n2)
{
int length = (N.BitLength + 7) / 8;
byte[] padded = GetPadded(n1, length);
byte[] input = GetPadded(n2, length);
digest.BlockUpdate(padded, 0, padded.Length);
digest.BlockUpdate(input, 0, input.Length);
byte[] output = new byte[digest.GetDigestSize()];
digest.DoFinal(output, 0);
return new BigInteger(1, output).Mod(N);
}
示例2: 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);
}
示例3: HashPaddedPair
private static BigInteger HashPaddedPair(IDigest digest, BigInteger N, BigInteger n1, BigInteger n2)
{
int padLength = (N.BitLength + 7) / 8;
byte[] n1_bytes = GetPadded(n1, padLength);
byte[] n2_bytes = GetPadded(n2, padLength);
digest.BlockUpdate(n1_bytes, 0, n1_bytes.Length);
digest.BlockUpdate(n2_bytes, 0, n2_bytes.Length);
byte[] output = new byte[digest.GetDigestSize()];
digest.DoFinal(output, 0);
return new BigInteger(1, output).Mod(N);
}
示例4: Encode
/// <summary>
/// Encode the stream with the given digest.
/// </summary>
/// <param name="data">The byte array to be encoded.</param>
/// <param name="digest">The digest to be used.</param>
/// <returns>Hashed value of the byte array as a hex string.</returns>
private static string Encode(byte[] data, IDigest digest)
{
digest.BlockUpdate(data, 0, data.Length);
byte[] output = new byte[digest.GetDigestSize()];
digest.DoFinal (output, 0);
return Hex.Encode(output);
}
示例5: Compute
public static byte[] Compute(IDigest hash, byte[] data)
{
var result = new byte[hash.GetDigestSize()];
hash.BlockUpdate(data, 0, data.Length);
hash.DoFinal(result, 0);
return result;
}
示例6: GetHash
private string GetHash(string s, IDigest algorithm)
{
var bytes = Encoding.UTF8.GetBytes(s);
algorithm.BlockUpdate(bytes,0,bytes.Length);
var res = new byte[algorithm.GetDigestSize()];
algorithm.DoFinal(res, 0);
return BitConverter.ToString(res).Replace("-", string.Empty);
}
示例7: 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;
}
示例8: Hash
private static byte[] Hash(byte[] data, IDigest digestAlgoritm)
{
digestAlgoritm.BlockUpdate(data, 0, data.Length);
var result = new byte[digestAlgoritm.GetDigestSize()];
digestAlgoritm.DoFinal(result, 0);
return result;
}
示例9: 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);
}
示例10: OaepEncoding
public OaepEncoding(IAsymmetricBlockCipher cipher, IDigest hash, IDigest mgf1Hash, byte[] encodingParams)
{
_engine = cipher;
_hash = hash;
_mgf1Hash = mgf1Hash;
_defHash = new byte[hash.GetDigestSize()];
if (encodingParams != null)
{
hash.BlockUpdate(encodingParams, 0, encodingParams.Length);
}
hash.DoFinal(_defHash, 0);
}
示例11: UpdateDigestIncludingSize
private static void UpdateDigestIncludingSize(IDigest digest, byte[] bytes)
{
digest.BlockUpdate(IntToByteArray(bytes.Length), 0, 4);
digest.BlockUpdate(bytes, 0, bytes.Length);
Arrays.Fill(bytes, (byte)0);
}
示例12: UpdateDigest
private static void UpdateDigest(IDigest digest, byte[] bytes)
{
digest.BlockUpdate(bytes, 0, bytes.Length);
Arrays.Fill(bytes, (byte)0);
}
示例13: Digest
public static byte[] Digest(IDigest d, byte[] b, int offset, int len) {
d.BlockUpdate(b, offset, len);
byte[] r = new byte[d.GetDigestSize()];
d.DoFinal(r, 0);
return r;
}
示例14: SignEcDsa
private byte[] SignEcDsa(IDigest digest, byte[] buffer, int length)
{
int digestSize = digest.GetDigestSize();
ECDsaSigner signer = new ECDsaSigner();
signer.Init(true, new ParametersWithRandom(PrivateKeyFactory.CreateKey(PrivateKey), _secureRandom));
digest.BlockUpdate(buffer, 0, length);
byte[] hash = new byte[digest.GetDigestSize()];
digest.DoFinal(hash, 0);
var signature = signer.GenerateSignature(hash);
byte[] res = new byte[digestSize * 2];
signature[0].ToByteArrayUnsigned().CopyTo(res, 0);
signature[1].ToByteArrayUnsigned().CopyTo(res, digestSize);
return res;
}
示例15: 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);*/
}