public static bool TestCert(CertificateInfo ci)
{
	bool bRes = true;

	try {
		X509Certificate2 cert;
		if (ci.Password != null)
			cert = new X509Certificate2(ci.FileName, ci.Password);
		else
			cert = new X509Certificate2(ci.FileName);
	
		if (!ci.Matches(cert)) bRes = false;

//		Console.WriteLine("ToString: " + cert.ToString());
//		Console.WriteLine("ToString(true): " + cert.ToString(true));

		X509Certificate2 certImp = new X509Certificate2();
		if (ci.Password != null)
			certImp.Import(ci.FileName, ci.Password, X509KeyStorageFlags.DefaultKeySet);
		else
			certImp.Import(ci.FileName);
		
		if (!ci.Matches(certImp)) bRes = false;
		
		
	}
	catch(Exception e)
	{
		bRes = false;
		Console.WriteLine("Exception is caught:" + Environment.NewLine + e.ToString());
	}

	return bRes;
}
    public static bool TestCert(CertificateInfo ci)
    {
        bool bRes = true;

        try {
            // read a certificate file to a byte array
            FileStream fs        = new FileStream(ci.FileName, FileMode.Open, FileAccess.Read);
            byte[]     certBytes = new byte[(int)fs.Length];
            fs.Read(certBytes, 0, certBytes.Length);

            X509Certificate2 cert;

            if (ci.Password != null)
            {
                cert = new X509Certificate2(certBytes, ci.Password);
            }
            else
            {
                cert = new X509Certificate2(certBytes);
            }

            if (!ci.Matches(cert))
            {
                bRes = false;
            }

//		Console.WriteLine("ToString: " + cert.ToString());
//		Console.WriteLine("ToString(true): " + cert.ToString(true));

            X509Certificate2 certImp = new X509Certificate2();

            if (ci.Password != null)
            {
                certImp.Import(certBytes, ci.Password, X509KeyStorageFlags.DefaultKeySet);
            }
            else
            {
                certImp.Import(certBytes);
            }

            if (!ci.Matches(certImp))
            {
                bRes = false;
            }
        }
        catch (Exception e)
        {
            bRes = false;
            Console.WriteLine("Exception is caught:" + Environment.NewLine + e.ToString());
        }

        return(bRes);
    }
Exemple #3
0
    public static bool TestCert(CertificateInfo ci)
    {
        bool bRes = true;

        try {
            X509Certificate2 cert;
            if (ci.Password != null)
            {
                cert = new X509Certificate2(ci.FileName, ci.Password);
            }
            else
            {
                cert = new X509Certificate2(ci.FileName);
            }

            if (!ci.Matches(cert))
            {
                bRes = false;
            }

//		Console.WriteLine("ToString: " + cert.ToString());
//		Console.WriteLine("ToString(true): " + cert.ToString(true));

            X509Certificate2 certImp = new X509Certificate2();
            if (ci.Password != null)
            {
                certImp.Import(ci.FileName, ci.Password, X509KeyStorageFlags.DefaultKeySet);
            }
            else
            {
                certImp.Import(ci.FileName);
            }

            if (!ci.Matches(certImp))
            {
                bRes = false;
            }
        }
        catch (Exception e)
        {
            bRes = false;
            Console.WriteLine("Exception is caught:" + Environment.NewLine + e.ToString());
        }

        return(bRes);
    }
public static bool TestCert(CertificateInfo ci)
{
	bool bRes = true;

	try {
		// read a certificate file to a byte array
		FileStream fs = new FileStream(ci.FileName, FileMode.Open, FileAccess.Read);
		byte[] certBytes = new byte[(int)fs.Length];
		fs.Read(certBytes, 0, certBytes.Length);
		
		X509Certificate2 cert;
		
		if (ci.Password != null)
			cert = new X509Certificate2(certBytes, ci.Password);
		else
			cert = new X509Certificate2(certBytes);
	
		if (!ci.Matches(cert)) bRes = false;

//		Console.WriteLine("ToString: " + cert.ToString());
//		Console.WriteLine("ToString(true): " + cert.ToString(true));

		X509Certificate2 certImp = new X509Certificate2();

		if (ci.Password != null)
			certImp.Import(certBytes, ci.Password, X509KeyStorageFlags.DefaultKeySet);
		else
			certImp.Import(certBytes);

		if (!ci.Matches(certImp)) bRes = false;
	
	}
	catch(Exception e)
	{
		bRes = false;
		Console.WriteLine("Exception is caught:" + Environment.NewLine + e.ToString());
	}

	return bRes;
}