如何从字节获取公钥?例如,我在Java上有公共密钥(使用EC算法生成,曲线为“ secp256r1”)及其编码的字节,如何在c#中从这些字节创建公共密钥?
答案 0 :(得分:0)
有多种方法可从保管库中提取密钥。我将以下内容用于同一目的。
var secret = keyVaultClient.GetSecretAsync(vaultAddress, "Honeywellpkiofflinetokenprime256v1cert").GetAwaiter().GetResult();
X509Certificate2Collection exportedCertCollection = new X509Certificate2Collection();
exportedCertCollection.Import(Convert.FromBase64String(secret.Value));
X509Certificate2 certFromSecret = exportedCertCollection.Cast<X509Certificate2>().Single(s => s.HasPrivateKey);
var publickeybyte = certFromSecret.GetPublicKey();
var publicekeybyte = certFromSecret.GetPublicKeyString();
var PublicKeyCNG= certFromSecret.GetECDsaPublicKey();
var privateECDsa = LoadPrivateKey(FromHexString(privateKey));
var publiccECDsa = LoadPublicKey(FromHexString(publicKey));
现在您可以使用相同的密钥来验证已签名的信息。