public async Task <string> GetPemKey(string keyVaultIdentifier) { AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider(); KeyVaultSecurityKey.AuthenticationCallback keyVaultAuthCallback = new KeyVaultSecurityKey.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback); KeyVaultClient client = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(keyVaultAuthCallback), EdnaExternalHttpClient.Create()); KeyBundle keyBundle = await client.GetKeyAsync(keyVaultIdentifier); RSAParameters rsaParameters = keyBundle.Key.ToRSAParameters(); return(ExportPublicKey(rsaParameters)); }
public async Task <JsonWebKey> GetJwk(string keyVaultIdentifier) { AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider(); KeyVaultSecurityKey.AuthenticationCallback keyVaultAuthCallback = new KeyVaultSecurityKey.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback); KeyVaultClient client = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(keyVaultAuthCallback), EdnaExternalHttpClient.Create()); KeyBundle keyBundle = await client.GetKeyAsync(keyVaultIdentifier); JsonWebKey jwk = new JsonWebKey(keyBundle.Key.ToString()); //Pruning to remove values for certian properties that are optional return(new JsonWebKey() { Kid = keyVaultIdentifier, Kty = JsonWebAlgorithmsKeyTypes.RSA, Alg = Microsoft.IdentityModel.Tokens.SecurityAlgorithms.RsaSha256, Use = Microsoft.IdentityModel.Tokens.JsonWebKeyUseNames.Sig, E = jwk.E, N = jwk.N }); }