SoFunction
Updated on 2025-03-07

Analyze the substring structure of digital signatures (get the digital signature time)


X509CertificateSubstring

#region File Description

#endregion

#region class modification record: modify a set of descriptions each time

#endregion

using System;
using .X509Certificates;

namespace
{
    /// <summary>
/// Substring structure of digital signature
    /// </summary>
    public class X509CertificateSubstring
    {
        //CN=Shenzhen DriveTheLife Software Technology , OU=Digital ID Class 3 - Microsoft Software Validation v2, O=Shenzhen DriveTheLife Software Technology , L=Shenzhen, S=Guangdong, C=CN
#region Private Field
        private string _CN = ;
        private string _OU = ;
        private string _O = ;
        private string _L = ;
        private string _S = ;
        private string _C = ;
        #endregion
#region Public read-only attribute
        public string CN { get { return _CN; } }
        public string OU { get { return _OU; } }
        public string O { get { return _O; } }
        public string L { get { return _L; } }
        public string S { get { return _S; } }
        public string C { get { return _C; } }
        #endregion
        public X509CertificateSubstring() { }

        /// <summary>
/// parse the Substring string into a structure
        /// </summary>
/// <param name="substring">Substring string</param>
        /// <returns>X509CertificateSubstring</returns>
        public static X509CertificateSubstring Parse(string substring)
        {
            X509CertificateSubstring xcs = new X509CertificateSubstring();
            string[] items = (',');
            foreach (var item in items)
            {
                if (().StartsWith("CN="))
                {
                    xcs._CN = ().Substring(3); continue;
                }
                if (().StartsWith("OU="))
                {
                    xcs._OU = ().Substring(3); continue;
                }
                if (().StartsWith("O="))
                {
                    xcs._O = ().Substring(2); continue;
                }
                if (().StartsWith("L="))
                {
                    xcs._L = ().Substring(2); continue;
                }
                if (().StartsWith("S="))
                {
                    xcs._S = ().Substring(2); continue;
                }
                if (().StartsWith("C="))
                {
                    xcs._C = ().Substring(2); continue;
                }
            }
            return xcs;
        }

        /// <summary>
/// parse the Substring string into a structure and return whether the digital signature exists or not
        /// </summary>
/// <param name="pyFile">Physical path to read the digitally signed file</param>
        /// <param name="xcs">X509CertificateSubstring</param>
        /// <returns>bool</returns>
        public static bool TryParse(string pyFile, out X509CertificateSubstring xcs)
        {
            bool result = true;
            xcs = new X509CertificateSubstring();
            string SubstringCN = ;
            X509Certificate cert = null;
            try
            {
                cert = (pyFile);
            }
            catch ( ce)
            {
//No digital signature, ignore this exception.
                result = false;
            }
            catch (Exception ex)
            {
                result = false;
                throw ex;
            }
            if (cert != null)
            {
                xcs = ();
            }
            return result;
        }

    }
}