证书信息

问题描述 投票:0回答:1

访问 Windows 证书存储时,您可以在“详细信息”选项卡中查看名为“描述”的属性。我无法使用 PowerShell 或 .NET 命令检索此信息。亲爱的社区,有人有这个信息吗?

$certs = Get-ChildItem Cert:\LocalMachine\My\
$certs[2] | select *

PSPath                   : Microsoft.PowerShell.Security\Certificate::LocalMachine\My\000000000000000
PSParentPath             : Microsoft.PowerShell.Security\Certificate::LocalMachine\My
PSChildName              : 000000000000000
PSDrive                  : Cert
PSProvider               : Microsoft.PowerShell.Security\Certificate
PSIsContainer            : False
EnhancedKeyUsageList     : {Authentification du serveur (1.3.6.1.5.5.7.3.1)}
DnsNameList              : {SERVER.DOMAIN.FR}
SendAsTrustedIssuer      : False
EnrollmentPolicyEndPoint : Microsoft.CertificateServices.Commands.EnrollmentEndPointProperty
EnrollmentServerEndPoint : Microsoft.CertificateServices.Commands.EnrollmentEndPointProperty
PolicyId                 : {0000}
Archived                 : False
Extensions               : {System.Security.Cryptography.Oid, System.Security.Cryptography.Oid, System.Security.Cryptography.Oid, System.Security.Cryptography.Oid...}
FriendlyName             : FRIENDLY_NAME
IssuerName               : System.Security.Cryptography.X509Certificates.X500DistinguishedName
NotAfter                 : 09/01/2027 16:38:30
NotBefore                : 10/01/2024 16:38:30
HasPrivateKey            : True
PrivateKey               : System.Security.Cryptography.RSACryptoServiceProvider
PublicKey                : System.Security.Cryptography.X509Certificates.PublicKey
RawData                  : {48, 130, 6, 211...}
SerialNumber             : 000000000000000
SubjectName              : System.Security.Cryptography.X509Certificates.X500DistinguishedName
SignatureAlgorithm       : System.Security.Cryptography.Oid
Thumbprint               : 000000000000000
Version                  : 3
Handle                   : 000000000000000
Issuer                   : CN=DOMAIN.FR, DC=DOMAIN, DC=FR
Subject                  : CN=SERVER.DOMAIN.FR, OU=DOMAIN, L=CITY, S=STATE, C=UK
.net powershell certificate
1个回答
0
投票

描述不是证书本身的一部分,而是特定于供应商的。对于 Windows,您可以使用此代码来拉取描述

$signature = @"
[DllImport("Crypt32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool CertGetCertificateContextProperty(
    IntPtr pCertContext,
    uint dwPropId,
    Byte[] pvData,
    ref uint pcbData
);
"@

Add-Type -MemberDefinition $signature -Namespace PKI -Name Crypt32
$pcbData = 0
# if the function returns False, then description is not specified.
$CERT_DESCRIPTION_PROP_ID = 13

$certs = Get-ChildItem Cert:\LocalMachine\My\ | Select-Object *,@{n='Description';e={
    if ([PKI.Crypt32]::CertGetCertificateContextProperty($_.Handle,$CERT_DESCRIPTION_PROP_ID,$null,[ref]$pcbData)) {
        # allocate a buffer to store property value
        $pvData = New-Object byte[] -ArgumentList $pcbData
        # call the function again to write actual data into allocated buffer
        [void][PKI.Crypt32]::CertGetCertificateContextProperty($_.Handle,$CERT_DESCRIPTION_PROP_ID,$pvData,[ref]$pcbData)
        # Description is null-terminated unicode string
        [Text.Encoding]::Unicode.GetString($pvData).TrimEnd()
    }
}}

参考已接受的答案这里

© www.soinside.com 2019 - 2024. All rights reserved.