C# 如何检查是否安装了ssl证书?

C# 如何检查是否安装了ssl证书?,c#,windows-phone-8,ssl-certificate,C#,Windows Phone 8,Ssl Certificate,我使用此代码安装自签名证书(用户必须确认安装) 是否可以检查证书是否已安装,这样我就不必在每次启动应用程序时都安装它了?为什么不尝试类似的方法来查找证书。还可以将此名称空间包含到您的项目系统中。Security.Cryptography.X509Certificates;如果您不能使用X509,您可以更改以下代码以使用不同类型的证书 private static X509Certificate2 GetCertificateFromStore(string certSN) {

我使用此代码安装自签名证书(用户必须确认安装)


是否可以检查证书是否已安装,这样我就不必在每次启动应用程序时都安装它了?

为什么不尝试类似的方法来查找证书。还可以将此名称空间包含到您的项目系统中。Security.Cryptography.X509Certificates;如果您不能使用X509,您可以更改以下代码以使用不同类型的证书

 private static X509Certificate2 GetCertificateFromStore(string certSN)
        {

            X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
            try
            {
                store.Open(OpenFlags.ReadOnly);
                X509Certificate2Collection col = store.Certificates;

                foreach (var currCert in col)
                {
                    var currSN = currCert.SerialNumber;
                    if (certSN.ToUpperInvariant() == currSN)
                    {
                        return currCert; // you found it return it
                        break;
                    }

                }

                return null; // you didnt now install it...
            }
            finally
            {
                store.Close();
            }


        }

为什么不试试这样的方法来找到证书呢。也可以在项目系统中包含这个名称空间。Security.Cryptography.X509Certificates;如果您不能使用X509,您可以更改以下代码以使用不同类型的证书

 private static X509Certificate2 GetCertificateFromStore(string certSN)
        {

            X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
            try
            {
                store.Open(OpenFlags.ReadOnly);
                X509Certificate2Collection col = store.Certificates;

                foreach (var currCert in col)
                {
                    var currSN = currCert.SerialNumber;
                    if (certSN.ToUpperInvariant() == currSN)
                    {
                        return currCert; // you found it return it
                        break;
                    }

                }

                return null; // you didnt now install it...
            }
            finally
            {
                store.Close();
            }


        }

证书可以通过多种方式进行比较,但最常见的两种方式是

  • 凭指纹
    • 公钥的加密散列
    • 根据请求计算–不存储在证书本身中
    • 所有证书都是唯一的
    • 使用抗冲突哈希算法()时很难伪造
  • 按序列号和发行人
    • 强制要求在使用PKI时保持唯一性
    • 由于无需计算,比较速度更快
    • 只有在验证链信任时才能信任。攻击者可以生成具有选定序列号和颁发者名称的自签名证书
代码:

X509Certificate cert1 = /* your cert */;
X509Certificate cert2 = /* your other cert */;

// assuming you are validating pki chain
// X509Certificate compares the serial number and issuer
bool matchUsingSerialAndIssuer = cert1.Equals(cert2);

// otherwise
bool publicKeyIsIdentical = cert1.GetCertHashString() == cert2.GetCertHashString();
// or easier to read if using X509Certificate2 (Thumbprint calls GetCertHashString)
// bool publicKeyIsIdentical = cert1.Thumbprint == cert2.Thumbprint;

证书可以通过多种方式进行比较,但最常见的两种方式是

  • 凭指纹
    • 公钥的加密散列
    • 根据请求计算–不存储在证书本身中
    • 所有证书都是唯一的
    • 使用抗冲突哈希算法()时很难伪造
  • 按序列号和发行人
    • 强制要求在使用PKI时保持唯一性
    • 由于无需计算,比较速度更快
    • 只有在验证链信任时才能信任。攻击者可以生成具有选定序列号和颁发者名称的自签名证书
代码:

X509Certificate cert1 = /* your cert */;
X509Certificate cert2 = /* your other cert */;

// assuming you are validating pki chain
// X509Certificate compares the serial number and issuer
bool matchUsingSerialAndIssuer = cert1.Equals(cert2);

// otherwise
bool publicKeyIsIdentical = cert1.GetCertHashString() == cert2.GetCertHashString();
// or easier to read if using X509Certificate2 (Thumbprint calls GetCertHashString)
// bool publicKeyIsIdentical = cert1.Thumbprint == cert2.Thumbprint;

你可以试着从证书存储中读取证书,通过它的序列号、颁发者等。你能给我一个提示吗?谢谢。事实上你自己也可以在谷歌上找到这个(这不是针对WP的,所以不能保证):谢谢,我知道有一个类。据我所知,这门课不适用于WP。嗨,你知道现在怎么做吗?我还想知道一些关于它的信息。你可以试着从证书存储中读取证书,通过它的序列号、颁发者等。你能告诉我怎么做吗?谢谢。事实上你自己也可以在谷歌上找到这个(这不是针对WP的,所以不能保证):谢谢,我知道有一个类。据我所知,这门课不适用于WP。嗨,你知道现在怎么做吗?我也想了解一些,谢谢。我认为我不能使用你的方法,因为WP8中没有课和。谢谢。我认为我不能使用您的方法,因为WP8中没有类和。