【问题标题】:Add-AzKeyVaultKey fails with message "Invalid provider type specified" when adding key to keyvault将密钥添加到 keyvault 时,Add-AzKeyVaultKey 失败并显示消息“指定的提供程序类型无效”
【发布时间】:2021-02-04 18:34:12
【问题描述】:

我正在尝试使用 Add-AzKeyVaultKey 将密钥添加到密钥库,但失败并显示消息“指定的提供程序类型无效”。

Add-AzKeyVaultKey : Invalid provider type specified.
At line:3 char:1
+ Add-AzKeyVaultKey -VaultName '$KeyVaultName' -Name 'alfalaval-as2-pri ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Add-AzKeyVaultKey], CryptographicException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.KeyVault.AddAzureKeyVaultKey

我可以成功地将证书(从 pfx)导入到 keyvault,但是从同一个 pfx 导入密钥时操作失败。

根据微软文档,应该是pfx文件(不支持PEM):Micsosoft, Add-AzKeyVaultKey

如果有人想试用,我已在此处 (keypair at filebin) 上传了一个示例虚拟密钥对。

示例代码

#Import certificate used for encryption
$Password = ConvertTo-SecureString -String "abcd1234" -AsPlainText -Force
Import-AzKeyVaultCertificate -VaultName "$KeyVaultName" -Name "as2-demo-certificate" -FilePath 'C:\mypath\as2-demo-cert.pfx' -Password $Password

#Importing key used for decryption
Add-AzKeyVaultKey -VaultName '$KeyVaultName' -Name 'as2-demo-private-key' -Destination 'Software' -KeyFilePath 'C:\mypath\as2-demo-cert.pfx' -KeyFilePassword $Password

任何帮助表示赞赏:)

【问题讨论】:

  • this 有帮助吗?
  • 是的,谢谢 - 成功了。我在从 powershell 生成证书时指定了提供程序。
  • 太棒了!很高兴听到它修复了。为了他人的利益,请考虑发布一个自我回答来解释更多关于此的内容。
  • 当然! :) 谢谢

标签: powershell import key azure-keyvault


【解决方案1】:

正如Theo 指出的here(了解更多详细信息),解决方案是在生成我们的密钥对时指定提供程序,因为 Add-AzKeyVaultKey cmdlet 仅支持下一代加密(CNG,CAPI2)提供程序。

点击here另一个包含更多细节的精彩帖子。

如果不指定提供程序,New-SelfSignedCertificate cmdlet 默认为“Microsoft Software Key Storage Provider”

支持的提供程序:“Microsoft RSA SChannel 加密提供程序”

示例

New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -KeyAlgorithm "RSA" -DnsName "test.local" -Subject "test.local" -FriendlyName "test-cng" -provider "Microsoft RSA SChannel Cryptographic Provider" -KeyExportPolicy "Exportable" -NotAfter (Get-Date).AddYears(10)

将其导出为 pfx 时,powershell cmdlet 解析它没有问题。 如果MS Documentation 指出这一点会很棒 - 会为我节省大量的故障排除:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-30
    • 2020-01-27
    • 2020-09-10
    • 2019-02-03
    • 1970-01-01
    • 2017-07-02
    相关资源
    最近更新 更多