当前位置: 首页>>代码示例>>C#>>正文


C# X509Certificate.Import方法代码示例

本文整理汇总了C#中X509Certificate.Import方法的典型用法代码示例。如果您正苦于以下问题:C# X509Certificate.Import方法的具体用法?C# X509Certificate.Import怎么用?C# X509Certificate.Import使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在X509Certificate的用法示例。


在下文中一共展示了X509Certificate.Import方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NegTest3

 public bool NegTest3(string fileName) { return NegTest(3, "Import(byte[])", fileName,
                                                              delegate(string fName)
                                                              {
                                                                  X509Certificate cer;
                                                                  cer = new X509Certificate();
                                                                  cer.Import(BytesFromFile(fName));
                                                                  return false;
                                                              } ); }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:8,代码来源:X509CertificateInvalidImports.cs

示例2: NegTest2

 public bool NegTest2(string fileName) { return NegTest(2, "Import(String,String,X509KeyStorageFlags)", fileName,
                                                              delegate(string fName)
                                                              {
                                                                  X509Certificate cer;
                                                                  cer = new X509Certificate();
                                                                  cer.Import(fName, "", X509KeyStorageFlags.DefaultKeySet);
                                                                  return false;
                                                              } ); }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:8,代码来源:X509CertificateInvalidImports.cs

示例3: NegTest1

 public bool NegTest1(string fileName) { return NegTest(1, "Import(String)", fileName,
                                                              delegate(string fName)
                                                              {
                                                                  X509Certificate cer;
                                                                  cer = new X509Certificate();
                                                                  cer.Import(fName);
                                                                  return false;
                                                              } ); }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:8,代码来源:X509CertificateInvalidImports.cs

示例4: VerifyImportNotSupported

 private static void VerifyImportNotSupported(X509Certificate c)
 {
     Assert.Throws<PlatformNotSupportedException>(() => c.Import(Array.Empty<byte>()));
     Assert.Throws<PlatformNotSupportedException>(() => c.Import(string.Empty));
     Assert.Throws<PlatformNotSupportedException>(() => c.Import(Array.Empty<byte>(), string.Empty, X509KeyStorageFlags.DefaultKeySet));
     Assert.Throws<PlatformNotSupportedException>(() => c.Import(Array.Empty<byte>(), new SecureString(), X509KeyStorageFlags.DefaultKeySet));
     Assert.Throws<PlatformNotSupportedException>(() => c.Import(string.Empty, string.Empty, X509KeyStorageFlags.DefaultKeySet));
     Assert.Throws<PlatformNotSupportedException>(() => c.Import(string.Empty, new SecureString(), X509KeyStorageFlags.DefaultKeySet));
 }
开发者ID:dotnet,项目名称:corefx,代码行数:9,代码来源:ImportTests.cs

示例5: DoValidate

    static bool DoValidate(FileInfo fi)
    {
        bool                        retVal;
        FileStream                  fs;
        StreamReader                fsr;
        IDictionary<string, string> certVals;
        X509Certificate             cer;

        retVal             = true;
        fs                 = File.Open(fi.FullName + ".bsl", FileMode.Open);
        fsr                = new StreamReader(fs);
        certVals           = new Dictionary<string, string>();

	// open baseline file and retain expected values
        while (fsr.Peek() >= 0)
        {
            string[] lr = fsr.ReadLine().Split(new char[] { '|' });
            certVals.Add(lr[0], lr[1]);
        }
        fs.Close();

        // X509Certificate.CreateFromCertFile(String)
        TestFramework.LogInformation("-- importing certificate using X509Certificate.CreateFromCertFile()");
        cer = X509Certificate.CreateFromCertFile(fi.FullName);
        if (!ValidateCertAgainstBaseline(certVals, cer))
        {
            retVal = false;
            TestFramework.LogError("011", "Certificate built with X509Certificate.CreateFromCertFile() failed");
        }

        // Import(String)
        TestFramework.LogInformation("-- importing certificate using .ctor() and Import(String)");
        cer = new X509Certificate();
        cer.Import(fi.FullName);
        if (!ValidateCertAgainstBaseline(certVals, cer))
        {
            retVal = false;
            TestFramework.LogError("011", "Certificate built with default .ctor and Import(string) failed");
        }

        // Import(String,String,X509KeyStorageFlags)
        TestFramework.LogInformation("-- importing certificate using .ctor() and Import(String,String,X509KeyStorageFlags)");
        cer = new X509Certificate();
        foreach (X509KeyStorageFlags ksf in m_allKeyStorageFlags)
        {
            cer.Import(fi.FullName, "", ksf);
            if (!ValidateCertAgainstBaseline(certVals, cer))
            {
                retVal = false;
                TestFramework.LogError("012", "Certificate built with default .ctor and Import(string, string, X509StorageKeys) failed for " + ksf.ToString());
            }
        }

        // Import(byte[])
        cer = new X509Certificate();
        TestFramework.LogInformation("-- importing certificate using .ctor() and Import(byte[])");
        cer.Import(BytesFromFile(fi.FullName));
        if (!ValidateCertAgainstBaseline(certVals, cer))
        {
            retVal = false;
            TestFramework.LogError("013", "Certificate built with default .ctor and Import(byte[]) failed");
        }

        // Import(byte[],String,X509KeyStorageFlags)
        TestFramework.LogInformation("-- importing certificate using .ctor() and Import(byte[],String,X509KeyStorageFlags)");
        cer = new X509Certificate();
        cer.Import(BytesFromFile(fi.FullName), "", X509KeyStorageFlags.DefaultKeySet);
        if (!ValidateCertAgainstBaseline(certVals, cer))
        {
            retVal = false;
            TestFramework.LogError("014", "Certificate built with default .ctor and Import(byte[],string,X509StorageKeys) failed");
        }


        // second case: validate string ctor
        TestFramework.LogInformation("-- importing certificate using .ctor(String)");
        cer = new X509Certificate(fi.FullName);
        if (!ValidateCertAgainstBaseline(certVals, cer))
        {
            retVal = false;
            TestFramework.LogError("015", "Certificate built with .ctor(String) failed");
        }


        // third case: validate string ctor with password
        TestFramework.LogInformation("-- importing certificate using .ctor(string,string) ");
        cer = new X509Certificate(fi.FullName, "");
        if (!ValidateCertAgainstBaseline(certVals, cer))
        {
            retVal = false;
            TestFramework.LogError("016", "Certificate built with .ctor(String,String) failed");
        }


        // fourth case: validate string ctor with password and KeyStorageFlags
        TestFramework.LogInformation("-- importing certificate using .ctor() (String,String,X509KeyStorageFlags)");
        foreach (X509KeyStorageFlags ksf in m_allKeyStorageFlags)
        {
            cer = new X509Certificate(fi.FullName, "", ksf);
            if (!ValidateCertAgainstBaseline(certVals, cer))
//.........这里部分代码省略.........
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:101,代码来源:X509CertificateRunSuite.cs

示例6: NegTest4

 public bool NegTest4(string fileName) { return NegTest(4, "Import(byte[],String,X509KeyStorageFlags)", fileName,
                                                              delegate(string fName)
                                                              {
                                                                  X509Certificate cer;
                                                                  cer = new X509Certificate();
                                                                  cer.Import(BytesFromFile(fName), "", X509KeyStorageFlags.DefaultKeySet);
                                                                  return false;
                                                              } ); }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:8,代码来源:X509CertificateInvalidImports.cs

示例7: CargarCertificadoFirmante

 public void CargarCertificadoFirmante(string path)
 {
     certificadoFirmante = new X509Certificate2 ();
     certificadoFirmante.Import (path);
 }
开发者ID:hamekoz,项目名称:hamekoz-sharp,代码行数:5,代码来源:TicketDeAcceso.cs


注:本文中的X509Certificate.Import方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。