简体   繁体   English

使用 MD5 哈希算法生成 ServicePartitionKey 很少返回 WindowsCryptographicException

[英]Generating a ServicePartitionKey using MD5 Hashing Algorithm seldomly return WindowsCryptographicException

We are using MD5 Hashing Algorithm for generating PartitionKey to route to a stateful Service.我们正在使用 MD5 哈希算法生成 PartitionKey 以路由到有状态服务。 For quite sometime we haven't seen any concerning issues in this approach.很长一段时间以来,我们在这种方法中没有看到任何令人担忧的问题。 But, upgrading to .NET 6 we are seldomly seeing WindowsCryptographicException in the logs while trying to route to Stateful Service.但是,升级到 .NET 6 我们在尝试路由到有状态服务时很少在日志中看到 WindowsCryptographicException。

Area/Component: Stateful Services, PartitionKey generator领域/组件:有状态服务、PartitionKey 生成器

To Reproduce重现

private readonly MD5 _md5 = MD5.Create();私人只读 MD5 _md5 = MD5.Create();

public long GetPartitionKey(string Id)
{
    var bytesToHash = Encoding.ASCII.GetBytes($"{Id}");

    var hash = _md5.ComputeHash(bytesToHash);
    var key = BitConverter.ToInt64(hash, 0);
    return key;
}

Expected behavior Shouldn't be returning any error.预期行为不应返回任何错误。 Observed behavior: {"Type":"WindowsCryptographicException","Message":"Unknown error (0xc1000008)","StackTrace":" at Internal.Cryptography.HashProviderCng.AppendHashData(ReadOnlySpan`1 source) at Internal.Cryptography.HashProvider.AppendHashData(Byte[] data, Int32 offset, Int32 count) at System.Security.Cryptography.HashAlgorithm.ComputeHash(Byte[] buffer) Screenshots If applicable, add screenshots to help explain your problem.观察到的行为:{"Type":"WindowsCryptographicException","Message":"Unknown error (0xc1000008)","StackTrace":" 在 Internal.Cryptography.HashProviderCng.AppendHashData(ReadOnlySpan`1 源)在 Internal.Cryptography.HashProvider。 AppendHashData(Byte[] data, Int32 offset, Int32 count) at System.Security.Cryptography.HashAlgorithm.ComputeHash(Byte[] buffer) 屏幕截图 如果适用,请添加屏幕截图以帮助解释您的问题。

Service Fabric Runtime Version: 8.0服务结构运行时版本:8.0

Environment:环境:

Azure Linux If this is a regression, which version did it regress from? Azure Linux 如果这是回归,它是从哪个版本回归的? After upgrading to .NET6升级到 .NET6 后

We used .NET6 with stateful service and used the MD5 Hashing algorithm, able to run and deployed without any exceptions我们使用.NET6 with stateful service,使用MD5 Hashing算法,可以无异常运行和部署

Try to run the Visual studio as "Administrator" Below are the Service Fabric versions installed *尝试以"Administrator"身份运行 Visual Studio 下面是安装的 Service Fabric 版本*

在此处输入图像描述在此处输入图像描述

在此处输入图像描述

Used the GetPartitionKey code with MD5将 GetPartitionKey 代码与 MD5 结合使用

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM