net6 'MD5CryptoServiceProvider' 已过时 处理方法
将项目升级到 .NET 6 后,编译器开始抱怨以下警告消息:
warning SYSLIB0021: “MD5CryptoServiceProvider”已过时:“Derived cryptographic types are obsolete. Use the Create method on the base type instead.”
这是导致此警告的代码:
public static string MD5Crypto(string key)
{
byte[] hash = (new ASCIIEncoding()).GetBytes(key);
using (var md5 = MD5CryptoServiceProvider())
hash = md5.ComputeHash(hash);
return (new ASCIIEncoding()).GetString(hash);
}
修复很简单:
public static string MD5Crypto(string key)
{
byte[] hash = (new ASCIIEncoding()).GetBytes(key);
using (var md5 = MD5.Create())
hash = md5.ComputeHash(hash);
return (new ASCIIEncoding()).GetString(hash);
}
关联项目
FreeSql QQ群:4336577
BA & Blazor QQ群:795206915
Maui Blazor 中文社区 QQ群:645660665
知识共享许可协议
本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。欢迎转载、使用、重新发布,但务必保留文章署名AlexChow(包含链接: https://github.com/densen2014 ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请与我联系 。
转载声明
本文来自博客园,作者:周创琳 AlexChow,转载请注明原文链接:https://www.cnblogs.com/densen2014/p/16826092.html
AlexChow
今日头条 | 博客园 | 知乎 | Gitee | GitHub


浙公网安备 33010602011771号