1 回答
TA贡献1840条经验 获得超5个赞
'certificateName' 与预期的模式 '^[\w]+-[\w]+$' 不匹配。
您可以调试代码并检查 Azure 密钥库中的指纹。在您的代码中,您从代码中获得的指纹与认证指纹不同。我使用以下代码获得了认证指纹。
X509Certificate2 x509 = new X509Certificate2();
x509.Import(cert.Cer);
var thumbprint = x509.Thumbprint;
下面是我用来将证书添加到 Azure 批处理帐户的演示代码。
var credentials = SdkContext.AzureCredentialsFactory.FromFile(@"cred file path");
var resourceGroup = "resourceGroup";
var accountName = "batchAccountName";
var subscriptionId = "subscriptionName";
var certificateIdentifier = "https://keyvaultName.vault.azure.net/certificates/certName/xxxxx";
var batchManagementClient = new BatchManagementClient(credentials)
{
SubscriptionId = subscriptionId
};
var azureServiceTokenProvider = new AzureServiceTokenProvider();
var keyVaultClient =
new KeyVaultClient(
new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
var cert = keyVaultClient.GetCertificateAsync(certificateIdentifier).Result;
X509Certificate2 x509 = new X509Certificate2();
x509.Import(cert.Cer);
var thumbprint = x509.Thumbprint;
var certConent = Convert.ToBase64String(cert.Cer);
var certName = $"SHA1-{thumbprint}";
var result= batchManagementClient.Certificate.CreateAsync(resourceGroup, accountName, certName, new CertificateCreateOrUpdateParametersInner
{
Thumbprint = thumbprint,
Data = certConent,
ThumbprintAlgorithm = "SHA1",
Format = CertificateFormat.Cer,
}).Result;
测试结果:
- 1 回答
- 0 关注
- 149 浏览
添加回答
举报