Ejemplo n.º 1
0
        /// <summary>
        /// If necessary, calls the Windows dialog box for the user to enter the digital certificate PIN code. Widely used in A3 digital certificates.
        /// </summary>
        /// <param name="certificate">The certificate</param>
        public static void AskForPIN(this X509Certificate2 certificate)
        {
            if (certificate == null)
            {
                throw new ArgumentNullException(nameof(certificate));
            }

            X509CertificateHelpers.SignXML(certificate, null, "<?xml version=\"1.0\" encoding=\"utf-8\"?><dummyTag/>");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sign a XML with a digital certificate.
        /// </summary>
        /// <param name="certificate">The certificate</param>
        /// <param name="elementNameRef">XML element to sign</param>
        /// <param name="xml">XML to sign</param>
        /// <param name="attributeRef">(Optional) Reference to use in the sign process</param>
        /// <returns></returns>
        public static String SignXML(this X509Certificate2 certificate, String elementNameRef, String xml, String attributeRef = "Id")
        {
            var docXML = new XmlDocument()
            {
                PreserveWhitespace = true
            };

            using (XmlTextReader xtr = new XmlTextReader(new MemoryStream(Encoding.UTF8.GetBytes(xml))))
            {
                docXML.Load(xtr);
            }

            return(X509CertificateHelpers.SignXML(certificate, elementNameRef, docXML, attributeRef));
        }