如何在 C# 中从 ECDsa 获取 public 密钥

How to get a public key from ECDsa in C#

在 C# 中,我可以创建一个 RSA public/private 密钥对...

RSA rsa = RSA.Create();

byte[] priKey = rsa.ExportRSAPrivateKey();
byte[] pubKey = rsa.ExportRSAPublicKey();

现在我想有效地使用ECDsa...

做同样的事情
ECDsa ecdsa = ECDsa.Create();

byte[] priKey = ecdsa.ExportECPrivateKey();
...

...但我似乎找不到允许导出 public 密钥的方法?

我想你正在寻找 ExportSubjectPublicKeyInfo()

var publicKey = ecdsa.ExportSubjectPublicKeyInfo();

The docs 说:

Exports the public-key portion of the current key in the X.509 SubjectPublicKeyInfo format

找到关于“SubjectPublicKeyInfo”的信息source

The Subject Public Key Info (SubjectPublicKeyInfo) field carries the Public Key component of its associated subject, as well as an indication of the algorithm, and any algorithm parameters, with which the public component is to be used.