使用API在Azure Key Vault中创建密钥
我在指定的订阅中通过创建了一个Azure密钥保管库.关注了这篇文章
I was created azure key vault through in the specified subscription. Followed this article,
https://docs.microsoft .com/zh-CN/rest/api/keyvault/keyvaultpreview/vaults/createorupdate#examples
当api调用时,天蓝色文件库成功创建.现在,我还需要为创建的Key Vault创建一个密钥.在创建天蓝色的密钥库时是否可以创建密钥?
And when the api called, azure vault created successfully. Now I also need to create a key for the created Key vault. Is it possible to create the key when the azure key vault creation?
在创建天蓝色的密钥库时是否可以创建密钥?
Is it possible to create the key when the azure key vault creation?
正如juunas所说,您需要单独拨打电话才能实现自己想要的目标.
As juunas said, you need to make a separate call to achieve what you want.
我用以下代码对其进行了测试,它可以正常工作. resourceUri是https://vault.azure.net
.有关更多详细信息,您可以参考此
I test it with the following code, it works correctly on my side. The resourceUri is https://vault.azure.net
. For more details, you could refer to this SO thread.
在Key vault
通道中,您需要Add policies
到注册的应用程序或用户.在Access Control
中,您需要add permission
到注册的应用程序或用户.
In Key vault
channel, you need to Add policies
to your registered application or user. And in Access Control
you need to add permission
to your registered application or user.
var appId = "0000000000000000000000000000000";
var secretKey = "******************************************";
var tenantId = "0000000000000000000000000000000";
var context = new AuthenticationContext("https://login.windows.net/" + tenantId);
ClientCredential clientCredential = new ClientCredential(appId, secretKey);
var tokenResponse = context.AcquireTokenAsync("https://vault.azure.net", clientCredential).Result;
var accessToken = tokenResponse.AccessToken;
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
var requestURl = "https://xxxxxx.vault.azure.net/keys/xxxx/create?api-version=2016-10-01";
string body = "{\"kty\": \"RSA\"}";
var stringContent = new StringContent(body, Encoding.UTF8, "application/json");
var response = client.PostAsync(requestURl, stringContent).Result;
}