Esempio n. 1
0
        public static SignedPropertiesType CreateSignedProperties(this QualifyingPropertiesType qualifyingProperties
                                                                  , XAdESSignedXml signedXml)
        {
            qualifyingProperties.SignedProperties = new SignedPropertiesType
            {
                Id = XsdSchemas.FormatId(signedXml.Signature.Id, "SignedProperties")
            };

            return(qualifyingProperties.SignedProperties);
        }
Esempio n. 2
0
        public static SignedPropertiesType CreateSignedProperties(this QualifyingPropertiesType qualifyingProperties
                                                                , XAdESSignedXml                signedXml)
        {
            qualifyingProperties.SignedProperties = new SignedPropertiesType
            {
                Id = XsdSchemas.FormatId(signedXml.Signature.Id, "SignedProperties")
            };

            return qualifyingProperties.SignedProperties;
        }
 /// <summary>
 /// Verify the signature against an asymetric 
 /// algorithm and return the result.
 /// </summary>
 /// <param name="eInvoice"></param>
 /// <param name="Key"></param>
 /// <returns></returns>
 /// <remarks>http://social.msdn.microsoft.com/Forums/hu-HU/netfxbcl/thread/d6a4fe9f-7d2e-419c-ab19-9e57c75ba90f</remarks>
 public bool CheckSignature()
 {
     XAdESSignedXml      signedXml = new XAdESSignedXml(this.signedDocument);
     XmlNamespaceManager nsmgr     = XsdSchemas.CreateXadesNamespaceManager(this.signedDocument);
     
     // Load the signature node.
     signedXml.LoadXml((XmlElement)this.signedDocument.SelectSingleNode("//ds:Signature", nsmgr));
     
     // Check the signature against the passed asymetric key
     // and return the result.
     return signedXml.CheckSignature();
 }
        /// <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);
        }