-1

how to get public key from bytes? for example, I have public key (generated with EC algorithm, curve "secp256r1") and its encoded bytes on java, How can I create public key from these bytes in c#?

  • What do you mean "public key"? Is that you want to know how to get Azure Key Vault key? – Jim Xu Feb 17 '20 at 08:13
  • yes, I stored one certificate inside the azure vault and i used that certificate to sign the self created jwt-token using signasync method. I want to extract the public key from the same certificate to verify the signatures of signed token – Bikramjit singh Feb 18 '20 at 11:34
  • Is that you want to export cer file from Azure key vault? – Jim Xu Feb 19 '20 at 01:32
  • No. I don't want to export any file from the key vault. – Bikramjit singh Mar 05 '20 at 08:14
  • I am using the getKeyAsync method to fetch the key from vault and I am getting the ky bundle from the vault. Inside the bundle key is in byte array so i wanted to convert the byte array to get correct key – Bikramjit singh Mar 05 '20 at 08:15

1 Answers1

0

There are different methods to fetch the key from the vault. I used the following for the same.

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

now you can use the same key to verify your signed information.