添加 Az 密钥保管库密钥失败,并在将密钥添加到密钥保管库时出现消息"Invalid provider type specified"



我正在尝试使用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): Microsoft, 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:mypathas2-demo-cert.pfx' -Password $Password
#Importing key used for decryption
Add-AzKeyVaultKey -VaultName '$KeyVaultName' -Name 'as2-demo-private-key' -Destination 'Software' -KeyFilePath 'C:mypathas2-demo-cert.pfx' -KeyFilePassword $Password

任何帮助都是感激的:)

正如Theo在这里指出的(阅读更多细节),解决方案是在生成密钥对时指定提供者,因为Add-AzKeyVaultKey cmdlet只支持下一代加密(CNG, CAPI2)提供者。

点击这里另一个伟大的帖子有更多的细节。

如果没有指定提供者,New-SelfSignedCertificate命令默认为"Microsoft Software Key Storage provider">

支持的提供商:"Microsoft RSA信道加密提供商">

New-SelfSignedCertificate -CertStoreLocation Cert:LocalMachineMy -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解析它没有问题。如果微软文档能指出这一点,那就太好了,这样我就能省下很多麻烦了:)

最新更新