假设你的意思是你想坚持一个钥匙插入OS密钥存储(的RSACryptoServiceProvider使用名为key),与CNG的界面有点不同:
private static ECDsa CreateOrOpenECDsaKey(string keyName)
{
CngKey key;
if (CngKey.Exists(keyName))
{
key = CngKey.Open(keyName);
}
else
{
// You can also specify options here, like if it should be exportable, in a
// different overload.
key = CngKey.Create(CngAlgorithm.ECDsaP521, keyName);
}
// The ECDsaCng constructor will duplicate the key reference, so we can close this one.
using (key)
{
return new ECDsaCng(key);
}
}
如果你的意思是你想做像RSAParameters一样的导出/导入,该功能存在于.NET Core中,但在.NET Framework中尚不存在。
感谢您的回答,它非常有用。我已经尝试过了,但是作为ECDsaCng值返回,我得到一个异常:“与ECDsaCng算法一起使用的密钥必须具有ECDsa算法组。\ r \ nParameter name:key”。我的密钥是用BouncyCastle库生成的,它似乎是作为ECDH而不是ECDSA创建的。我必须在这方面找出答案。 – santiPipes
@santiPipes已修复.NET Framework 4.6.2(http://referencesource.microsoft.com/#System.Core/System/Security/Cryptography/ECDsaCng.cs,bab9826847a21b79) – bartonjs
我明白了,非常感谢@bartonjs。这意味着我必须在将要执行该软件的所有计算机上安装新框架,不是吗?我想这不是只解决框架4.6.2编译(我知道,愚蠢的问题) – santiPipes