假设我正在使用此代码生成哈希:
static void Main(string[] args) {
string id = Guid.Parse("8681941A-76C2-4120-BC34-F800B5AAB5A5".ToLower()).ToString();
string date = DateTime.Today.ToString("yyyy-MM-dd");
Console.WriteLine(id);
Console.WriteLine(date);
using (System.Security.Cryptography.SHA512Managed hashTool =
new System.Security.Cryptography.SHA512Managed()) {
Byte[] PasswordAsByte = System.Text.Encoding.UTF8.GetBytes(string.Concat(id, date));
Byte[] EncryptedBytes = hashTool.ComputeHash(PasswordAsByte);
hashTool.Clear();
Console.WriteLine(Convert.ToBase64String(EncryptedBytes));
}
Console.ReadLine();
}
在一个真实世界的示例中,我将生成带有 GUID 和日期的哈希,正如您在示例中看到的那样。我将从数据库中获取这些值。
使用这种方法是否有可能获得具有不同值的相同哈希结果?
编辑:
正如我所指出的,我将从数据库中提取值。如您所料,Guid 是唯一的 id 键(如果我没有遇到奇迹并且 sql server 多次为我生成相同的 Guid)。datetime 值将作为记录的付款到期日。我在这里演示过,DateTime.Today
但我绝对不会在产品上使用它。