Nessa aula vou Mostrar como Assinar um Documento Xml This lesson will show how Subscribe to a XML Document Cette leçon montrera comment Abonnez-vous à un document XML //-- //Buscar arquivo xml a assinar // search xml file to sign // rechercher ujn fichier xml pourr signer _xml_assinar is string=fLoadText("D:\arquivo_xml\43160603850874000126550010000035551000142204-nfe.xml",foUnicode) EDT_xml=_xml_assinar sRefuri is string="infNFe" chavenfe is string="NFe43160603850874000126550010000035551000142204" s_retorno is string=assinar_nfe(_xml_assinar,sRefuri,chavenfe) IF s_retorno=-1 THEN EDT_xml_assinado="Erro assinar" ELSE EDT_xml_assinado=s_retorno END //-- PROCEDURE assinar_nfe(_recebe_xml,_refUri,_ChNfe)
//_refUri= (sRefUri IS STRING = "infNFe") clX509certi is X509Certificate2("D:\certificado_2016\certificado.pfx","senha") clDoc is System.Xml.XmlDocument; clDoc.LoadXml(_recebe_xml) // Ler um arquivo Xml // read an xml file // lire un fichir xml // //certificado com endereco e senha //certificate with address and password //le certificat avec adresse et mot de pass //ver se Refuri existe //Refers to see there //fait référence à y voir qtderefuri is int= clDoc.GetElementsByTagName(_refUri).Count IF (qtderefuri) =0 THEN //nao existe // does not exists // ne pas exister ELSE //cria um objeto assinado // creat a signed object // créer un objet signé VrSignedXml is SignedXml(clDoc) // adiciona a chave do certificado // add the key certificate // ajouter le certificat de clé VrSignedXml.SigningKey = clX509certi.PrivateKey // Cria a referencia para assinatura // creates a reference to signature // crée une référence à la signature Reference is Reference //= new Reference(); Reference.Uri = "#" + _ChNfe // adiciona um XmlDsigEnvelopedSignatureTransform para a assinatura // add a XmlDsigEnvelopedSignatureTransform for signature // ajouter un XmlDsigEnvelopedSignatureTransform à la signature Env is XmlDsigEnvelopedSignatureTransform Reference.AddTransform(Env) c14 is XmlDsigC14NTransform Reference.AddTransform(c14) // adiciona a referencia no xml assinado // add the reference in xlm signed // ajouter la référence en xml singé VrSignedXml.AddReference(Reference) // Cria a chave // creates the key // crée la clé VrkeyInfo is KeyInfo // carrega o certificado em um keyinfox509 e adiciona ao keyinfo // load the certificate in a keyinfo x509 and add to keyinfo // chager le certificat dans un x509 keyinfo et ajouter à kyinfo VrkeyInfo.AddClause(new KeyInfoX509Data(clX509certi)) // adiciona o keyinfo ao xml assinado // add keyinfo the xml signed // ajouter keyinfo le xml signé VrSignedXml.KeyInfo = VrkeyInfo VrSignedXml.ComputeSignature() // busca a representacao XML da assinatura e salva no XML // search the xml representantion of the signature and saved in xml // rechercher la représentation xml de la signature et enregistré en xml xmlDigitalSignature is System.Xml.XmlElement dynamic = VrSignedXml.GetXml() // adiciona a assinatura no documento // add the signature in the document // ajouter la signature dans le document clDoc.DocumentElement.AppendChild(clDoc.ImportNode(xmlDigitalSignature, True)) //salva o documento assinado // save the signed document // enregistrer le document signé RESULT clDoc.get_InnerXml()
END RESULT -1 //--
//Blog com Video e Exemplo http://windevdesenvolvimento.blogspot.com.br/2016/06/curso-windev-certificado-007-assinatura.html https://www.youtube.com/watch?v=uVLpstx5cRk
|