本文整理汇总了C#中System.Security.Cryptography.MD5.Initialize方法的典型用法代码示例。如果您正苦于以下问题:C# MD5.Initialize方法的具体用法?C# MD5.Initialize怎么用?C# MD5.Initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.MD5
的用法示例。
在下文中一共展示了MD5.Initialize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateNameBasedUUID
/**
* Method for generating name-based UUIDs, using the standard
* name-based generation method described in the UUID specs,
* and the caller supplied hashing method.
*
* Note that this method is not synchronized, so caller has to make
* sure the digest object will not be accessed from other threads.
*
* Note that if you call this method directly (instead of calling
* the version with one less argument), you have to make sure that
* access to 'hash' is synchronized; either by only generating UUIDs
* from one single thread, or by using explicit sync'ing.
*
* @param nameSpaceUUID UUID of the namespace, as defined by the
* spec. UUID has 4 pre-defined "standard" name space strings
* that can be passed to UUID constructor (see example below).
* Note that this argument is optional; if no namespace is needed
* (for example when name includes namespace prefix), null may be
* passed.
* @param name Name to base the UUID on; for example,
* IP-name ("www.w3c.org") of the system for UUID.NAMESPACE_DNS,
* URL ("http://www.w3c.org/index.html") for UUID.NAMESPACE_URL
* and so on.
* @param digest Instance of MessageDigest to use for hashing the name
* value. hash.reset() will be called before calculating the has
* value, to make sure digest state is not random and UUID will
* not be randomised.
*
* @return UUID generated using name-based method based on the
* arguments given.
*
* Example:
* <code>
* UUID uuid = gen.generateNameBasedUUID(
* new UUID(UUID.NAMESPACE_DNS, "www.w3c.org"));
* </code>
*/
public UUID GenerateNameBasedUUID(UUID nameSpaceUUID, String name,
MD5 digest)
{
if (name == null)
{
throw new NullReferenceException("Name parameter was null.");
}
digest.Initialize();
byte[] hash;
if (nameSpaceUUID != null)
{
byte[] a1 = nameSpaceUUID.ToByteArray();
byte[] a2 = Encoding.UTF8.GetBytes(name);
byte[] rv = new byte[a1.Length + a2.Length];
System.Buffer.BlockCopy(a1, 0, rv, 0, a1.Length);
System.Buffer.BlockCopy(a2, 0, rv, a1.Length, a2.Length);
hash = digest.ComputeHash(rv);
}
else
{
hash = digest.ComputeHash(Encoding.UTF8.GetBytes(name));
}
return new UUID(UUID.TYPE_NAME_BASED, hash);
}
示例2: RFC1321_e
public void RFC1321_e (string testName, MD5 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);
byte[] output = hash.TransformFinalBlock (input, input.Length - 1, 1);
Assert.AreEqual (input [input.Length - 1], output [0], testName + ".e.1");
AssertEquals (testName + ".e.2", result, hash.Hash);
// required or next operation will still return old hash
hash.Initialize ();
}
示例3: RFC1321_d
public void RFC1321_d (string testName, MD5 hash, byte[] input, byte[] result)
{
byte[] output = hash.TransformFinalBlock (input, 0, input.Length);
AssertEquals (testName + ".d.1", input, output);
AssertEquals (testName + ".d.2", result, hash.Hash);
// required or next operation will still return old hash
hash.Initialize ();
}
示例4: RFC1321_c
public void RFC1321_c (string testName, MD5 hash, byte[] input, byte[] result)
{
MemoryStream ms = new MemoryStream (input);
byte[] output = hash.ComputeHash (ms);
AssertEquals (testName + ".c.1", result, output);
AssertEquals (testName + ".c.2", result, hash.Hash);
// required or next operation will still return old hash
hash.Initialize ();
}
示例5: RFC1321_b
public void RFC1321_b (string testName, MD5 hash, byte[] input, byte[] result)
{
byte[] output = hash.ComputeHash (input, 0, input.Length);
AssertEquals (testName + ".b.1", result, output);
AssertEquals (testName + ".b.2", result, hash.Hash);
// required or next operation will still return old hash
hash.Initialize ();
}
示例6: DigestFile
DataHash DigestFile( MD5 provider, string filepath, Regex findDateTime)
{
var rv = new DataHash() {
Result = DataHashResult.FileNotFound,
InputName = filepath,
};
if (!FileUtils.Exists(filepath)) return rv;
provider.Initialize();
var fs = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read);
using (var bs = new BufferedStream(fs))
{
Logging.Emit("digest {0}", filepath);
rv.Hash = new SoapHexBinary(provider.ComputeHash(bs)).ToString();
rv.Result = DataHashResult.Ok;
if (findDateTime != null) {
// check include cache for this file
if (includeCache.ContainsEntry(rv.Hash, F_NotDateTime))
{
return rv;
}
if (includeCache.ContainsEntry(rv.Hash, F_HasDateTime))
{
rv.Result = DataHashResult.ContainsTimeOrDate;
return rv;
}
bs.Seek(0, SeekOrigin.Begin);
using (var ts = new StreamReader(bs))
{
string line = null;
do
{
line = ts.ReadLine();
if (line == null)
{
includeCache.WaitOne();
try
{
includeCache.AddTextFileContent(rv.Hash, F_NotDateTime, "");
}
finally
{
includeCache.ReleaseMutex();
}
break;
}
if (findDateTime.IsMatch(line))
{
rv.Result = DataHashResult.ContainsTimeOrDate;
includeCache.WaitOne();
try
{
includeCache.AddTextFileContent(rv.Hash, F_HasDateTime, "");
}
finally
{
includeCache.ReleaseMutex();
}
break;
}
} while (true);
}
}
}
rv.Result = DataHashResult.Ok;
return rv;
}