c# - 在符合 FIPS 的环境中使用 DevForce 时出现异常
问题描述
我们有一些客户希望在“ FIPS 模式”下在 Windows 上运行我们的软件(使用 DevForce)。似乎 DevForce 完成的大多数加密默认情况下都符合 FIPS,但我们遇到了 DevForce 所做的一些散列的问题。具体来说,调用 down 的代码AesCryptoProvider.CalcStringHash
如下所示:
/// <summary>
/// Returns a hash encoded as a string with the chars (A-Z,A-z,0-9,_) only.
/// </summary>
/// <remarks>
/// Under the covers this method returns an 128 bit hash code calculated
/// using SHA1. This code is then encoded into an approx Base64 encode
/// of the chars listed above. This will usually be approx 28 chars in length,
/// which may then be truncated based on the maxChars parameter. This
/// method can process approx 100K 300 char strings a second.
/// </remarks>
/// <param name="stringToHash"></param>
/// <param name="maxChars"></param>
/// <returns></returns>
public string CalcStringHash(string stringToHash, int maxChars)
{
return CodingFns.EncodeBase64(new SHA1Managed().ComputeHash(Encoding.Unicode.GetBytes(stringToHash))).Substring(0, maxChars).Replace("=", "").Replace("/", "_d").Replace("+", "_p");
}
该方法直接实例化一个SHA1Managed
实例,不幸的是,该类不符合 FIPS。
这是上下文的完整堆栈跟踪:
Exception: System.InvalidOperationException: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.
at System.Security.Cryptography.SHA1Managed..ctor()
at IdeaBlade.Core.PlatformServices.AesCryptoProvider.CalcStringHash(String stringToHash, Int32 maxChars)
at IdeaBlade.Core.DynamicTypeInfo.GetUniqueToken()
at IdeaBlade.Core.DynamicTypeInfo.BuildDynamicTypeName()
at IdeaBlade.Core.DynamicTypeInfo..ctor(TypeShape typeShape)
at IdeaBlade.Core.DynamicTypeInfo.FindOrCreate(IEnumerable`1 propertyNames, IEnumerable`1 propertyTypes)
at IdeaBlade.Linq.AnonymousProjectionSelector.GetDynamicTypeInfo()
at IdeaBlade.Linq.AnonymousProjectionSelector.ToLambdaExpression(Type delegateType)
at IdeaBlade.Linq.QueryableExtensions.Select[TSource](IQueryable`1 source, IProjectionSelector selector)
at My.Company.ServerClass.MyRemoteServerMethod(IPrincipal principal, EntityManager serverEm, Object[] rawArgs)
是否有任何解决方法可以让 DevForce 在 FIPS 模式下工作?或者这是可以在未来版本中添加的东西?
我注意到对该方法的评论谈论的是性能。如果这是一种性能关键的方法并且切换到 FIPS 投诉替代方案会导致性能下降,那么它可能是一个可配置的选项?我们只有一位客户抱怨 FIPS,但有更多的客户关心性能,所以我不想让那些不关心 FIPS 的人的事情变慢。
解决方案
这是一个错误,我们可以修复它(希望在下一个版本中)。此散列逻辑仅在为“动态”类型生成名称时使用,该名称在处理匿名类型和动态查询时使用。您可以通过投影到自定义类型而不是匿名类型来解决此错误,否则没有解决方法可以避免该问题。
如果性能是一个问题,而且很可能不是因为这种散列现在仅用于动态类型名称,我们可以查看在 FIPS/非 FIPS 兼容提供程序之间进行选择的切换。
推荐阅读
- pandas - 在python中获取最近合并前后30分钟的记录
- terminal - 使用 systemd-run 限制多个进程的 CPU 和内存使用的语法?
- python - 在将列表输入谷歌表格时,我应该如何修复列表索引超出范围错误?
- sendgrid - 收件人服务器阻止电子邮件在 SendGrid 中传递
- notificationcenter - 在 macOS Big Sur 中使用代码切换 DoNotDisturb
- forms - R Web Scraping rvest 表单 submit_form
- java - 如何为转置矩阵编写方法?
- android - 如何在 Android 应用上获取 STUN 或 TURN 服务器?
- javascript - 自定义 Kendo 下拉列表消息以替换“未找到数据”
- excel - 使用 VBA 格式化页脚