Exemple #1
0
        public static void ParseCertificate()

        {
            try
            {
                // User code goes here
                byte[] certBytes = GetCertificate();

                X509Certificate cert = new X509Certificate(certBytes);

                Console.WriteLine("Certificate Details:-");

                Console.WriteLine("Issuer:" + cert.Issuer);
                Console.WriteLine("Subject:" + cert.Subject);
                Console.WriteLine("EffectiveDate:" + cert.GetEffectiveDate().ToString());
                Console.WriteLine("EffectiveDate:" + cert.GetExpirationDate().ToString());

                if (cert.GetRawCertData().Equals(GetCertificate()))
                {
                    Console.WriteLine("Raw data ok");
                }
                else
                {
                    Console.WriteLine("Raw data different");
                }
            }
            catch (Exception ex)
            {
                // Do whatever please you with the exception caught
            }
        }
Exemple #2
0
        public static void Main()
        {
            X509Certificate cert = new X509Certificate(x509RsaPem2048bytesCertificate);

            Console.WriteLine("Certificate Details:");

            Console.WriteLine($"Issuer: {cert.Issuer}");
            Console.WriteLine($"Subject: {cert.Subject}");
            Console.WriteLine($"Effective Date: {cert.GetEffectiveDate()}");
            Console.WriteLine($"Expiry Date:: {cert.GetExpirationDate()}");

            // check raw data against buffer
            if (cert.GetRawCertData().Equals(Encoding.UTF8.GetBytes(x509RsaPem2048bytesCertificate)))
            {
                Console.WriteLine("Raw data checks");
            }
            else
            {
                Console.WriteLine("******************************");
                Console.WriteLine("ERROR: Raw data is different!!");
                Console.WriteLine("******************************");
            }

            Thread.Sleep(Timeout.Infinite);
        }
Exemple #3
0
        public static void Main()
        {
            //////////////////////////////////////////////////////////////////////////////////
            // certificate in PEM format (as a string in the app)
            X509Certificate cert = new X509Certificate(x509RsaPem2048bytesCertificate);

            Console.WriteLine("Certificate Details:");

            Console.WriteLine($"Issuer: {cert.Issuer}");
            Console.WriteLine($"Subject: {cert.Subject}");
            Console.WriteLine($"Effective Date: {cert.GetEffectiveDate()}");
            Console.WriteLine($"Expiry Date:: {cert.GetExpirationDate()}");

            // check raw data against buffer
            if (cert.GetRawCertData().GetHashCode() != Encoding.UTF8.GetBytes(x509RsaPem2048bytesCertificate).GetHashCode())
            {
                Console.WriteLine("Raw data checks");
            }
            else
            {
                Console.WriteLine("******************************");
                Console.WriteLine("ERROR: Raw data is different!!");
                Console.WriteLine("******************************");
            }

            /////////////////////////////////////////////////////////////////////////////////////
            // add certificate in CER format (as a managed resource)
            cert = new X509Certificate(Resources.GetBytes(Resources.BinaryResources.DigiCertGlobalRootCA));

            Console.WriteLine("DigiCert Certificate Details:");

            Console.WriteLine($"Issuer: {cert.Issuer}");
            Console.WriteLine($"Subject: {cert.Subject}");
            Console.WriteLine($"Effective Date: {cert.GetEffectiveDate()}");
            Console.WriteLine($"Expiry Date:: {cert.GetExpirationDate()}");

            // check raw data against buffer
            if (cert.GetRawCertData().GetHashCode() != Resources.GetBytes(Resources.BinaryResources.DigiCertGlobalRootCA).GetHashCode())
            {
                Console.WriteLine("Raw data checks");
            }
            else
            {
                Console.WriteLine("******************************");
                Console.WriteLine("ERROR: Raw data is different!!");
                Console.WriteLine("******************************");
            }

            Thread.Sleep(Timeout.Infinite);
        }
        public MFTestResults GetEffectiveDateNewCert()
        {
            MFTestResults testResult = MFTestResults.Fail;

            Log.Comment("Get the Effective Date field of a valid certificate");

            try
            {
                X509Certificate cert = new X509Certificate(CertificatesAndCAs.newCert);
                DateTime        date = cert.GetEffectiveDate();

                Log.Comment("TODO: Validate the DateTime here");
                Log.Comment("The DateTime is: " + date.ToString());
                testResult = MFTestResults.Pass;
            }
            catch (Exception e)
            {
                Log.Comment("Incorrectly threw exception calling Date: " + e.ToString());
                testResult = MFTestResults.Fail;
            }

            return(testResult);
        }
        public MFTestResults GetEffectiveDateNewCert()
        {
            MFTestResults testResult = MFTestResults.Fail;

            Log.Comment("Get the Effective Date field of a valid certificate");

            try
            {
                X509Certificate cert = new X509Certificate(CertificatesAndCAs.newCert);
                DateTime date = cert.GetEffectiveDate();

                Log.Comment("TODO: Validate the DateTime here");
                Log.Comment("The DateTime is: " + date.ToString());
                testResult = MFTestResults.Pass;
            }
            catch (Exception e)
            {
                Log.Comment("Incorrectly threw exception calling Date: " + e.ToString());
                testResult = MFTestResults.Fail;
            }

            return testResult;
        }