使用c#:“ import .pfx证书”使用c#:“证书内容”无法读取。
我一直在尝试将证书进出来,将证书导入Azure的KeyVault服务,但没有成功。该证书已成功地通过Azure Portal正确导入,我什至可以通过X509Certificate2加载它,并且似乎运行良好。
事实是,一旦我执行importcertificateasync
方法,它就会引发一个例外:
无法读取指定的PKCS#12 X.509证书内容。 请检查证书是否有效PKCS#12格式。状态:400 (不良要求)
实际上,我实际上是从本地存储中加载证书的file.readallBytes
,创建importCertificateOptions
和调用import> importcertificatificateasync
方法>离开。
var certificate = new X509Certificate2(data, password);
if (!certificate.HasPrivateKey)
return;
var client = new CertificateClient(new Uri("https://myenvironment-dev.vault.azure.net/"), new DefaultAzureCredential());
var importOptions = new ImportCertificateOptions("importedFromCode", data);
var result = await client.ImportCertificateAsync(importOptions, cancellationToken);
我在做什么错?
I have been trying back and forth importing a certificate into Azure's KeyVault service with no success. The certificate has been correctly imported through Azure Portal successfully and I can even load it through X509Certificate2 and seems to work well.
Thing is that once I execute the ImportCertificateAsync
method it throws an exception saying:
The specified PKCS#12 X.509 certificate content can not be read.
Please check if certificate is in valid PKCS#12 format. Status: 400
(Bad Request)
I'm actually loading the certificate from a local storage with a File.ReadAllBytes
, creating an ImportCertificateOptions
and calling ImportCertificateAsync
method right away.
var certificate = new X509Certificate2(data, password);
if (!certificate.HasPrivateKey)
return;
var client = new CertificateClient(new Uri("https://myenvironment-dev.vault.azure.net/"), new DefaultAzureCredential());
var importOptions = new ImportCertificateOptions("importedFromCode", data);
var result = await client.ImportCertificateAsync(importOptions, cancellationToken);
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
傻我,我实际上不是设置证书的密码!
Silly me I wasn't actually setting the certificate's password!