本文整理汇总了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;
} ); }
示例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;
} ); }
示例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;
} ); }
示例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));
}
示例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))
//.........这里部分代码省略.........
示例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;
} ); }
示例7: CargarCertificadoFirmante
public void CargarCertificadoFirmante(string path)
{
certificadoFirmante = new X509Certificate2 ();
certificadoFirmante.Import (path);
}