Ejemplo n.º 1
0
        /// <summary>
        /// Signs the electronic invoice using the given certificate & RSA key.
        /// </summary>
        /// <param name="certificate">The certificate.</param>
        /// <param name="key">The RSA Key.</param>
        /// <param name="signerRole">Rol del "firmante" de la factura</param>
        /// <returns>The XAdES signature verifier.</returns>
        private XAdESSignatureVerifier Sign(X509Certificate2 certificate, RSA key, ClaimedRole signerRole)
        {
            if (certificate == null)
            {
                throw new ArgumentNullException("certificate cannot be null");
            }
            if (key == null)
            {
                throw new ArgumentNullException("key cannot be null");
            }

            var document  = this.ToXmlDocument();
            var signedXml = new XAdESSignedXml(document);

            // Set the key to sign
            signedXml.SigningKey = key;

            signedXml.SetSignatureInfo()
            .SetSignerRole(signerRole)                                          // XAdES Signer Role
            .SetKeyInfo(certificate, (RSA)certificate.PublicKey.Key)            // Key Info
            .ComputeSignature();                                                // Compute Signature

            // Import the signed XML node
            document.DocumentElement.AppendChild(document.ImportNode(signedXml.GetXml(), true));

            return(new XAdESSignatureVerifier(document));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Signs the electronic invoice using the given certificate & RSA key.
        /// </summary>
        /// <param name="certificate">The certificate.</param>
        /// <param name="key">The RSA Key.</param>
        /// <param name="signerRole">Rol del "firmante" de la factura</param>
        /// <returns>The XAdES signature verifier.</returns>
        public XAdESSignatureVerifier Sign(X509Certificate2 certificate, ClaimedRole signerRole)
        {
            if (certificate == null)
            {
                throw new ArgumentNullException("certificate cannot be null");
            }

            return(this.Sign(certificate, (RSA)certificate.PrivateKey, signerRole));
        }
Ejemplo n.º 3
0
        public static SignedSignaturePropertiesType SetSignerRole(this SignedSignaturePropertiesType signedSignatureProperties
                                                                  , ClaimedRole signerRole)
        {
            signedSignatureProperties.SignerRole = new SignerRoleType
            {
                ClaimedRoles = new List <ClaimedRole> {
                    signerRole
                }
            };

            return(signedSignatureProperties);
        }
Ejemplo n.º 4
0
        public static SignedSignaturePropertiesType SetSignerRole(this SignedSignaturePropertiesType signedSignatureProperties
                                                                , ClaimedRole                        signerRole)
        {
            signedSignatureProperties.SignerRole = new SignerRoleType
            {
                ClaimedRoles = new List<ClaimedRole> { signerRole }
            };

            return signedSignatureProperties;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Signs the electronic invoice using the given certificate & RSA key.
        /// </summary>
        /// <param name="certificate">The certificate.</param>
        /// <param name="key">The RSA Key.</param>
        /// <param name="signerRole">Rol del "firmante" de la factura</param>
        /// <returns>The XAdES signature verifier.</returns>
        private XAdESSignatureVerifier Sign(X509Certificate2 certificate, RSA key, ClaimedRole signerRole)
        {
            if (certificate == null)
            {
                throw new ArgumentNullException("certificate cannot be null");
            }
            if (key == null)
            {
                throw new ArgumentNullException("key cannot be null");
            }

            var document  = this.ToXmlDocument();
            var signedXml = new XAdESSignedXml(document);

            // Set the key to sign
            signedXml.SigningKey = key;

            signedXml.SetSignatureInfo()
                     .SetSignerRole(signerRole)                                 // XAdES Signer Role
                     .SetKeyInfo(certificate, (RSA)certificate.PublicKey.Key)   // Key Info
                     .ComputeSignature();                                       // Compute Signature
            
            // Import the signed XML node 
            document.DocumentElement.AppendChild(document.ImportNode(signedXml.GetXml(), true));            

            return new XAdESSignatureVerifier(document);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Signs the electronic invoice using the given certificate & RSA key.
        /// </summary>
        /// <param name="certificate">The certificate.</param>
        /// <param name="key">The RSA Key.</param>
        /// <param name="signerRole">Rol del "firmante" de la factura</param>
        /// <returns>The XAdES signature verifier.</returns>
        public XAdESSignatureVerifier Sign(X509Certificate2 certificate, ClaimedRole signerRole)
        {
            if (certificate == null)
            {
                throw new ArgumentNullException("certificate cannot be null");
            }

            return this.Sign(certificate, (RSA)certificate.PrivateKey, signerRole);
        }
Ejemplo n.º 7
0
        public XAdESSignedXml SetSignerRole(ClaimedRole signerRole)
        {
            this.signerRole = signerRole;

            return(this);
        }
Ejemplo n.º 8
0
        public XAdESSignedXml SetSignerRole(ClaimedRole signerRole)
        {
            this.signerRole = signerRole;

            return this;
        }