将密钥添加到 keyvault 时,Add-AzKeyVaultKey 失败并显示消息 "Invalid provider type specified"
Add-AzKeyVaultKey fails with message "Invalid provider type specified" when adding key to keyvault
我正在尝试使用 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)成功导入到密钥库,但是当从同一个 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
感谢任何帮助:)
与 Theo pointed out (阅读更多详细信息)一样,解决方案是在生成密钥对时指定提供程序,因为 Add-AzKeyVaultKey cmdlet 仅支持下一代加密技术(CNG、CAPI2)提供程序。
单击 另一个很棒的 post,了解更多详细信息。
如果您不指定提供商,New-SelfSignedCertificate cmdlet 默认为“Microsoft 软件密钥存储提供商”
支持的提供程序:“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 指出了这一点,那就太好了 - 会为我省去大量的故障排除工作:)
我正在尝试使用 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)成功导入到密钥库,但是当从同一个 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
感谢任何帮助:)
与 Theo pointed out
单击
如果您不指定提供商,New-SelfSignedCertificate cmdlet 默认为“Microsoft 软件密钥存储提供商”
支持的提供程序:“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 指出了这一点,那就太好了 - 会为我省去大量的故障排除工作:)