簡體   English   中英

如何在 C# 證書回調中查看“簽名哈希算法”?

[英]How do I view "Signature hash algorithm" in C# certificate callback?

我有一台使用以下證書進行 SSL/TLS 通信的服務器:

證書查看器

在我的 C# 代碼中,我使用自定義證書驗證回調以編程方式查看此證書的屬性,如下所示:

private static bool CertificateValidationCallBack(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
    // Certificate2 is better than Certificate1, right?
    X509Certificate2 cert = (X509Certificate2)certificate;            

    Console.WriteLine("Certificate Subject   : " + cert.Subject);
    Console.WriteLine("Certificate Issuer    : " + cert.Issuer);
    // So on and so forth...
}

但是,我的問題是我似乎看不到“簽名哈希算法”屬性。 cert.SignatureAlgorithm.FriendlyName返回RSASSA-PSS ,並且

new System.Security.Cryptography.Oid(cert.GetKeyAlgorithm()).FriendlyName)

只返回RSA 這些屬性似乎都沒有給我在 GUI 中看到的“sha256”屬性。 我如何歸還該財產?

編輯:我在 Cryptography.SE 上發現了這個相關問題,它解釋了 Microsoft 的證書查看器 GUI 有點不穩定且不符合標准,但如果是這種情況,那么我也想變得不穩定。 我想知道如何以與 GUI 相同的方式報告“sha256”。

08/13 更新:從另一個角度來看,當我使用命令時

certutil.exe -dump cert.cer

結果摘錄:

Signature Algorithm:
    Algorithm ObjectId: 1.2.840.113549.1.1.10 RSASSA-PSS
    Algorithm Parameters:
    0000  30 34 a0 0f 30 0d 06 09  60 86 48 01 65 03 04 02
    0010  01 05 00 a1 1c 30 1a 06  09 2a 86 48 86 f7 0d 01
    0020  01 08 30 0d 06 09 60 86  48 01 65 03 04 02 01 05
    0030  00 a2 03 02 01 20
            2.16.840.1.101.3.4.2.1 sha256 (sha256NoSign)
            05 00
            1.2.840.113549.1.1.8 mgf1
                2.16.840.1.101.3.4.2.1 sha256 (sha256NoSign)
                05 00
            0x20 (32)

我當然希望我知道如何為自己找到那些 OID(sha256 的)……而不用解析實際的 certutil 命令的輸出。

從您的 DER 字節來看,這些是簽名算法。

2a 86 48 86 f7 0d 01 01 08

我知道這些是簽名算法。 但是,我不知道如何分析這些字節。

我認為最后一個字節表示哈希算法。 我用openssl測試,當我用sha256、sha384、sha5512生成證書時,最后一個字節從0b->0c->0d改變了。 請讓我知道,當你想通了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM