本文整理汇总了C#中System.Security.Cryptography.HashAlgorithm.Initialize方法的典型用法代码示例。如果您正苦于以下问题:C# HashAlgorithm.Initialize方法的具体用法?C# HashAlgorithm.Initialize怎么用?C# HashAlgorithm.Initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.HashAlgorithm
的用法示例。
在下文中一共展示了HashAlgorithm.Initialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartTests
protected int StartTests(HashAlgorithm hash, byte[] input, byte[] result)
{
try {
byte[] ch = hash.ComputeHash(input, 0, input.Length);
if (!ArrayEquals(ch, result))
AddError("HB-ST1");
} catch {
AddError("HB-ST2");
}
try {
// feed input byte-by-byte
for(int i = 0; i < input.Length - 1; i++) {
hash.TransformBlock(input, i, 1, input, i);
}
if (input.Length > 0)
hash.TransformFinalBlock(input, input.Length - 1, 1);
else
hash.TransformFinalBlock(input, 0, 0);
if (!ArrayEquals(hash.Hash, result)) {
AddError("HB-ST3");
Console.WriteLine(Encoding.ASCII.GetString(input));
}
} catch {
AddError("HB-ST4");
} finally {
hash.Initialize();
}
return 4;
}
示例2: FIPS186_b
public void FIPS186_b(string testName, HashAlgorithm hash, byte[] input, byte[] result)
{
byte[] output = hash.ComputeHash (input, 0, input.Length);
Assert.AreEqual (result, output, testName + ".b.1");
Assert.AreEqual (result, hash.Hash, testName + ".b.2");
// required or next operation will still return old hash
hash.Initialize ();
}
示例3: GetDigestedBytes
internal byte[] GetDigestedBytes(HashAlgorithm hash)
{
this.m_c14nDoc.WriteHash(hash, DocPosition.BeforeRootElement, this.m_ancMgr);
hash.TransformFinalBlock(new byte[0], 0, 0);
byte[] buffer = (byte[]) hash.Hash.Clone();
hash.Initialize();
return buffer;
}
示例4: FIPS186_c
public void FIPS186_c(string testName, HashAlgorithm hash, byte[] input, byte[] result)
{
MemoryStream ms = new MemoryStream (input);
byte[] output = hash.ComputeHash (ms);
Assert.AreEqual (result, output, testName + ".c.1");
Assert.AreEqual (result, hash.Hash, testName + ".c.2");
// required or next operation will still return old hash
hash.Initialize ();
}
示例5: FIPS186_d
public void FIPS186_d(string testName, HashAlgorithm hash, byte[] input, byte[] result)
{
hash.TransformFinalBlock (input, 0, input.Length);
// LAMESPEC or FIXME: TransformFinalBlock doesn't return HashValue !
// AssertEquals( testName + ".d.1", result, output );
Assert.AreEqual (result, hash.Hash, testName + ".d");
// required or next operation will still return old hash
hash.Initialize ();
}
示例6: ComputeSha1Hash
/// <summary>
/// Computes the Sha1 hash value for the specified byte array.
/// </summary>
/// <param name="input">The byte-array to compute the hash value for.</param>
/// <returns>The computed hash value.</returns>
public static byte[] ComputeSha1Hash(byte[] input)
{
byte[] hash = null;
using (HashAlgorithm sha1 = new HashAlgorithm(HashAlgorithmType.SHA1))
{
sha1.Initialize();
hash = sha1.ComputeHash(input);
}
return hash;
}
示例7: Checksum
/// <summary>
/// Initialize a new checksum object.
/// </summary>
/// <param name="alg">The checksumming algorithm to use.</param>
public Checksum(Algorithm alg)
{
switch (alg)
{
case Algorithm.SHA0:
hash = new SHA0();
break;
case Algorithm.SHA1:
hash = HashAlgorithm.Create("SHA1");
break;
case Algorithm.MD5:
hash = HashAlgorithm.Create("MD5");
break;
}
hash.Initialize();
this.alg = alg;
}
示例8: TestComputeHash
public static bool TestComputeHash(HashAlgorithm hash, byte[] data, byte[] digest)
{
hash.Initialize();
if (!CompareBytes(hash.ComputeHash(data), digest))
{
Log.Comment("ComputeHash test failed");
return false;
}
return true;
}
示例9: MyRSA
public MyRSA()
{
m_hasher = MySHA256.Create();
m_hasher.Initialize();
}
示例10: TestHash
// tests a hash algorithm instance
public static bool TestHash(HashAlgorithm hash)
{
bool bRes = true;
// decide on the number of passes
int nPasses = m_Rnd.Next(MAX_PASSES) + 1;
Log.Comment("Doing " + nPasses + " passes...");
while (0 != nPasses--)
{
// init the hash object
hash.Initialize();
// create a random data blob
int nSize = m_Rnd.Next(MAX_SIZE);
byte[] abBlob = new byte[nSize];
Log.Comment("Test buffer size is " + nSize);
// first try ComputeHash
byte[] hash1 = hash.ComputeHash(abBlob);
// Log.Comment("Hash1:");
// PrintByteArray(hash1);
// now try stream
hash.Initialize();
byte[] hash2 = hash.TransformFinalBlock(abBlob, 0, abBlob.Length);
//CryptoStream cs = new CryptoStream(CryptoStream.Null, hash, CryptoStreamMode.Write);
//cs.Write(abBlob, 0, abBlob.Length);
//cs.Close();
//byte[] hash2 = hash.Hash;
// Log.Comment("Hash2:");
// PrintByteArray(hash2);
if (Compare(hash1, hash2))
{
Log.Comment(" OK.");
}
else
{
bRes = false;
Log.Comment(" FAILED. Hashes are different.");
}
}
return bRes;
}
示例11: CompareHashes
public static bool CompareHashes(HashAlgorithm algorithm1, HashAlgorithm algorithm2, byte[] data)
{
algorithm1.Initialize();
algorithm2.Initialize();
byte[] hash1 = algorithm1.ComputeHash(data);
byte[] hash2 = algorithm2.ComputeHash(data);
if (!CompareBytes(hash1, hash2))
{
Log.Comment("ERROR - HASH VALUE MISCOMPARISON!\n");
Log.Comment("Algorithm 1 : " + algorithm1.ToString());
Log.Comment("Algorithm 2 : " + algorithm2.ToString());
Log.Comment("Data: " + ByteArrayToString(data));
return false;
}
return true;
}
示例12: GenerateHash
// Generate the hash value for this assembly using a given algorith.
public byte[] GenerateHash(HashAlgorithm hashAlg)
{
if(hashAlg == null)
{
throw new ArgumentNullException("hashAlg");
}
byte[] rawData = RawData;
if(rawData == null)
{
return null;
}
hashAlg.Initialize();
return hashAlg.ComputeHash(rawData);
}
示例13: UnsaltedCrypt
static string UnsaltedCrypt(HashAlgorithm algorithm, byte[] password)
{
try
{
algorithm.Initialize();
algorithm.TransformBlock(password, 0, password.Length, password, 0);
algorithm.TransformFinalBlock(new byte[0], 0, 0);
string crypt = Convert.ToBase64String(algorithm.Hash);
return crypt;
}
finally
{
algorithm.Clear();
}
}
示例14: Hashing
public Hashing(HashAlgorithm hashAlgorithm)
{
_hashAlgorithm = hashAlgorithm;
_hashAlgorithm.Initialize();
}
示例15: FIPS186_e
public void FIPS186_e(string testName, HashAlgorithm hash, byte[] input, byte[] result)
{
byte[] copy = new byte [input.Length];
for (int i=0; i < input.Length - 1; i++)
hash.TransformBlock (input, i, 1, copy, i);
hash.TransformFinalBlock (input, input.Length - 1, 1);
// LAMESPEC or FIXME: TransformFinalBlock doesn't return HashValue !
// AssertEquals (testName + ".e.1", result, output);
Assert.AreEqual (result, hash.Hash, testName + ".e");
// required or next operation will still return old hash
hash.Initialize ();
}