大网数据广告活动
服务器运维问答

How to remove the CA root certificate from a pfx file in Windows?

· 52CE 我爱测

On a windows 2012 R2 and a Windows 10 machine there is a pfx file which contains the certificate chain for the server. I created this file using Windows MMC certificate export tool. The choices were export all certificates in the…

问题原文

原帖链接 · ciso · CC BY-SA 3.0

On a windows 2012 R2 and a Windows 10 machine there is a pfx file which contains the certificate chain for the server. I created this file using Windows MMC certificate export tool. The choices were export all certificates in the chain if possible or only the one certificate. The chain contains the root, two intermediary and then my server certificate.

I would like to remove the CA root certificate since the client should already have it, but leave the intermediary certificates.

How do you edit a pfx file to remove the one root certificate?

已采纳解答

原帖链接 · Crypt32 · CC BY-SA 3.0

You can do this with few lines of PowerShell code (no OpenSSL is required):

$path = "Put the path to a pfx file here"
$password = "Put password here"
$pfx = New-Object Security.Cryptography.X509Certificates.X509Certificate2Collection
# import pfx to X509Certificate2 collection
$pfx.Import([IO.File]::ReadAllBytes($path), $password, "Exportable")
# remove first root (self-signed) certificate
if ($pfx.Count -gt 1) {
    for ($i = 0; $i -lt $pfx.Count; $i++) {
        if ($pfx[$i].Issuer -eq $pfx[$i].Subject) {
            [void]$pfx.RemoveAt($i); break
        }
    }
}
# write back pfx to a file
$bytes = $pfx.Export("pfx", $password)
[IO.File]::WriteAllBytes($path, $bytes)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-05-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。