ASP.NET 5 创建 RSA 密钥,

ASP.NET 5 Creating RSA key,

我正在尝试在我的 ASP.NET 5 应用程序中使用基于令牌的身份验证创建 WebApi。我正在按照这些步骤 进行操作。 但是我已经陷入了第一个创建 RSA 密钥的困境。

RSACryptoServiceProvider myRSA = new RSACryptoServiceProvider(2048);

产生编译错误The type 'RSACryptoServiceProvider' exists in both 'System.Security.Cryptography.Csp' and 'System.Security.Cryptography.RSA'

当我将 "System.Security.Cryptography.RSA": "4.0.0-beta-22819" 添加到我的 project.json 错误消息时,它会变为 The type 'RSACryptoServiceProvider' exists in both 'System.Security.Cryptography.RSA' and 'mscorlib'

命名空间 System.Security.Cryptography.RSASystem.Security.Cryptography.Csp 都不可用。

我该如何解决?

已更新

这样做:

System.Security.Cryptography.RSACryptoServiceProvider myRSA = new System.Security.Cryptography.RSACryptoServiceProvider(2048);

或者您必须删除冲突的导入名称空间并且只 "using System.Security.Cryptography"

如果你使用的是ASP.NET 5 Core 那么你需要检查这个问题 关于如何让 Crypt 工作:

或从您的项目中删除 "dnxcore50"。