本文整理汇总了C#中IDigest.DoFinal方法的典型用法代码示例。如果您正苦于以下问题:C# IDigest.DoFinal方法的具体用法?C# IDigest.DoFinal怎么用?C# IDigest.DoFinal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDigest
的用法示例。
在下文中一共展示了IDigest.DoFinal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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);
}
示例4: 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);
}
示例5: 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;
}
示例6: 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;
}
示例7: 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);
}
示例8: 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);
}
示例9: 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);
}
示例10: TestDigestDoFinal
private void TestDigestDoFinal(IDigest digest)
{
byte[] hash = new byte[digest.GetDigestSize()];
digest.DoFinal(hash, 0);
for (int i = 0; i <= digest.GetDigestSize(); ++i)
{
byte[] cmp = new byte[2 * digest.GetDigestSize()];
Array.Copy(hash, 0, cmp, i, hash.Length);
byte[] buf = new byte[2 * digest.GetDigestSize()];
digest.DoFinal(buf, i);
if (!Arrays.AreEqual(cmp, buf))
{
Fail("sha3 offset DoFinal on " + digest.AlgorithmName);
}
}
}
示例11: CalculateKey
/**
* Computes the final Key according to the standard routine: Key = H(S)
* @param digest The Digest used as the hashing function H
* @param N Modulus used to get the pad length
* @param S The secret calculated by both sides
* @return
*/
public static BigInteger CalculateKey(IDigest digest, BigInteger N, BigInteger S)
{
int padLength = (N.BitLength + 7) / 8;
byte[] _S = GetPadded(S, padLength);
digest.BlockUpdate(_S, 0, _S.Length);
byte[] output = new byte[digest.GetDigestSize()];
digest.DoFinal(output, 0);
return new BigInteger(1, output);
}
示例12: vectorTest
private void vectorTest(
IDigest digest,
int count,
byte[] resBuf,
byte[] input,
byte[] expected)
{
digest.BlockUpdate(input, 0, input.Length);
digest.DoFinal(resBuf, 0);
if (!AreEqual(resBuf, expected))
{
Fail("Vector " + count + " failed got " + Hex.ToHexString(resBuf));
}
}
示例13: Digest
public static byte[] Digest(Stream data, IDigest messageDigest) {
byte[] buf = new byte[8192];
int n;
while ((n = data.Read(buf, 0, buf.Length)) > 0) {
messageDigest.BlockUpdate(buf, 0, n);
}
byte[] r = new byte[messageDigest.GetDigestSize()];
messageDigest.DoFinal(r, 0);
return r;
}
示例14: VerifyEcDsa
private bool VerifyEcDsa(IDigest digest, X9ECParameters curveParameter, byte[] buffer, int length, byte[] signature)
{
int digestSize = digest.GetDigestSize();
ECDomainParameters dParams = new ECDomainParameters(
curveParameter.Curve,
curveParameter.G,
curveParameter.N,
curveParameter.H,
curveParameter.GetSeed());
ECPoint q = dParams.Curve.CreatePoint(new BigInteger(1, PublicKey, 0, digestSize), new BigInteger(1, PublicKey, digestSize, digestSize), false);
ECPublicKeyParameters parameters = new ECPublicKeyParameters(q, dParams);
var signer = new ECDsaSigner();
signer.Init(false, parameters);
digest.BlockUpdate(buffer, 0, length);
byte[] hash = new byte[digest.GetDigestSize()];
digest.DoFinal(hash, 0);
return signer.VerifySignature(hash, new BigInteger(1, signature, 0, digestSize), new BigInteger(1, signature, digestSize, digestSize));
}
示例15: 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;
}