gpt4 book ai didi

PowerShell 获取带有密码 PFX 文件的证书指纹

转载 作者:行者123 更新时间:2023-12-02 22:54:06 35 4
gpt4 key购买 nike

我正在尝试使用以下代码获取受密码保护的 pfx 文件的指纹:

function Get-CertificateThumbprint {
#
# This will return a certificate thumbprint, null if the file isn't found or throw an exception.
#

param (
[parameter(Mandatory = $true)][string] $CertificatePath,
[parameter(Mandatory = $false)][string] $CertificatePassword
)

try {
if (!(Test-Path $CertificatePath)) {
return $null;
}

if ($CertificatePassword) {
$sSecStrPassword = ConvertTo-SecureString -String $CertificatePassword -Force –AsPlainText
}

$certificateObject = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$certificateObject.Import($CertificatePath, $sSecStrPassword);

return $certificateObject.Thumbprint
} catch [Exception] {
#
# Catch accounts already added.
throw $_;
}
}

当我运行它时,我收到此错误:

Cannot find an overload for "Import" and the argument count: "2".
At C:\temp\test.ps1:36 char:9
+ $certificateObject.Import($CertificatePath, $sSecStrPassword);
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest

有人可以帮我解决这个问题吗?

谢谢大家。 :-)

最佳答案

根据this SuperUser response ,在 PS 3.0 中有 Get-PfxCertificate command为此:

 Get-PfxCertificate -FilePath Certificate.pfx 

关于PowerShell 获取带有密码 PFX 文件的证书指纹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26877356/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com