简体   繁体   English

Powershell“X509Certificate2Collection”使用“3”参数调用“导入”时出现异常:“找不到请求的对象

[英]Powershell "X509Certificate2Collection" Exception calling "Import" with "3" argument(s): "Cannot find the requested object

I have the below piece of code to download cert from Azure Key Vault.我有以下代码可以从 Azure Key Vault 下载证书。

   $secretName = "TestCert"
    $kvSecret = Get-AzureKeyVaultSecret -VaultName $vaultName -Name $certificateName
    $kvSecretBytes = [System.Convert]::FromBase64String($kvSecret.SecretValueText)
    $certCollection = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2Collection
    $certCollection.Import($kvSecretBytes,$null, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)

But While importing cert to the certCollection the import method is throwing below error.但是在将证书导入 certCollection 时,导入方法抛出以下错误。

Exception calling "Import" with "3" argument(s): "Cannot find the requested object.
"
At C:\Users\abc\Desktop\test2.ps1:8 char:1
+ $certCollection.Import($kvSecretBytes,$null,[System.Security.Cryptogr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : CryptographicException     

Greatly appreciate help with this.非常感谢对此的帮助。 Thanks谢谢

Change the code like this and you are good to go!像这样更改代码,您就可以开始了!

    $secretName = "TestCert"
    $kvSecret = Get-AzureKeyVaultSecret -VaultName $vaultName -Name $certificateName
    $kvSecretBytes = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($kvSecret.SecretValueText))
    $jsonCert = ConvertFrom-Json($kvSecretBytes)
    $certBytes = [System.Convert]::FromBase64String($jsonCert.data)
    $certCollection = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2Collection
    $certCollection.Import($certBytes,$jsonCert.password,[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Powershell上传X509证书-错误“找不到所需的对象” - upload X509 certificate using powershell - error 'Cannot find the requested object' 在 x509Certificates object PowerShell 中找不到“AuthorityKeyIdentifier”值 - Cannot find “AuthorityKeyIdentifier” value in x509Certificates object PowerShell Powershell 错误:使用“2”参数调用“批准”的异常:值不能是 null - Powershell Error: Exception Calling “Approve” with “2” argument(s): Value cannot be null 使用“1”参数调用“发送”的异常:“根据验证程序,远程证书无效。PowerShell - Exception calling “Send” with “1” argument(s): "The remote certificate is invalid according to the validation procedure. PowerShell Powershell:使用“ 3”参数调用“ AttachDatabase”的异常 - Powershell: Exception calling “AttachDatabase” with “3” argument(s) PowerShell:使用“7”参数调用“GetListItems”异常 - PowerShell: Exception calling “GetListItems” with “7” argument(s) 使用“1”参数调用“SetAccessRule”的异常::: Powershell 错误 - Exception calling "SetAccessRule" with "1" argument(s) ::: Powershell Error 无法使用 powershell 从章鱼库访问 ssl 证书作为 X509Certificate2 对象 - Unable to access ssl certificate from octopus library as X509Certificate2 object using powershell PowerShell导入的dll无法正常工作:使用“ 0”参数调用“ ReadLookupTables”的异常:“对象引用未设置为对象的实例 - PowerShell imported dll not working: Exception calling “ReadLookupTables” with “0” argument(s): "Object reference not set to an instance of an object PowerShell 导出 AD 用户 x509 证书并为用户导入 ADUC - PowerShell export AD user x509 certificate and import into ADUC for the user
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM