【发布时间】:2019-08-27 05:21:45
【问题描述】:
我正在尝试实现一种检测重复文件的方法。我有一个 MD5 散列方法(让我们忽略 MD5 被破坏的事实)如下:
using(MD5 hasher = MD5.Create())
using(FileStream fs = File.OpenRead("SomeFile"))
{
byte[] hashBytes = hasher.ComputeHash(fs);
string hashString = string.Join(string.Empty, hashBytes.Select(x => x.ToString("X2")));
}
我可以像这样简单地创建一个Guid,而不是从hashBytes 中创建一个string 吗?
Guid hashGuid = new Guid(hashBytes);
它仍然有效还是我会失去唯一性?
【问题讨论】:
-
它们都是 128 位
-
使用 MD5 实际上是第 3 版 GUID:stackoverflow.com/questions/20342058/which-uuid-version-to-use 第 3 版 GUID 中有几个字节是硬编码的,但我没有运气找到对确切细节的引用那一刻。