EC从天蓝色密钥库中提取的公共密钥字节中的公共密钥

时间:2020-02-17 07:43:29

标签: c# azure azure-keyvault public-key ecdsa

如何从字节获取公钥?例如,我在Java上有公共密钥(使用EC算法生成,曲线为“ secp256r1”)及其编码的字节,如何在c#中从这些字节创建公共密钥?

1 个答案:

答案 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));

现在您可以使用相同的密钥来验证已签名的信息。