Cobol Foro
Navegación en el Foro
Retroceder   Cobol Foro Entornos de desarrollo y compiladores Cobol COBOL - General Object-Oriented COBOL
Object-Oriented COBOL COBOL orientado a objetos. ISO/2002-2014
 
Otros temas que te pueden interesar
Tema Autor Foro Respuestas Último post
[Duda] Incluir Certificado Digital em Faturas PDF Celina PowerCOBOL y COM/OLE 3 22 de julio de 2024 18:59
[Duda] Libro IVA Digital (Argentina) Alejo Gonzalez AcuCobol 7 14 de enero de 2021 10:23
[Sintaxis] Generar archivo xml en utf-8 Fito PowerCOBOL (ActiveX, v4 - v11) 4 30 de julio de 2017 00:44
[Sintaxis] XML en Windev Dasije WinDev 0 20 de septiembre de 2016 00:49
[Sintaxis] Crear Archivo Xml Anthony AcuCobol 7 25 de febrero de 2016 22:46

Respuesta

  #1
Antiguo 23 de febrero de 2017, 12:47
Kuk
Administrador
Última Actividad 19.09.2026 20:11
Posts Posts: 2.500
Likes enviados Enviados: 1037
Likes recibidos Recibidos: 1207
Arrow Firma digital sobre XML
1 Inactivo Inactivo

Citación del post de Eslopes
System.Security.Cryptography.Xml namespace allows you to digitally sign an XML document or part of it. The following example was converted into OO Cobol using a MSDN C# sample. The original C# code has been commented out so you can compare how far from C# logic OO Cobol is...see for yourself!
Código COBOL:
  1.  program-id. main as "ConsoleApplication5.Main".
  2.        
  3.  environment division.
  4.  configuration section.
  5.  repository.
  6.    class ClassCspParameters             as "System.Security.Cryptography.CspParameters"
  7.    class ClassXmlDocument               as "System.Xml.XmlDocument"
  8.    class ClassXmlNode                   as "System.Xml.XmlNode"
  9.    class ClassRSACryptoServiceProvider as "System.Security.Cryptography.RSACryptoServiceProvider"
  10.    class ClassSignedXml                 as "System.Security.Cryptography.Xml.SignedXml"
  11.    class ClassXmlReference             as "System.Security.Cryptography.Xml.Reference"
  12.    class ClassXmlDsigEnvSignatureTrans
  13.               as "System.Security.Cryptography.Xml.XmlDsigEnvelopedSignatureTransform"
  14.    class ClassXmlElement               as "System.Xml.XmlElement"
  15.    class SystemString                   as "System.String"
  16.    property StringEmpty                 as "Empty"
  17.    property KeyContainer               as "KeyContainerName"
  18.    property PreserveWhitespace         as "PreserveWhitespace"
  19.    property SigningKey                 as "SigningKey"
  20.    property Uri                         as "Uri"
  21.    property DocumentElement             as "DocumentElement".
  22.    
  23.   data division.
  24.   working-storage section.
  25.         01  cspParams    usage object reference ClassCspParameters.
  26.         01  xmlDoc       usage object reference ClassXmlDocument.
  27.         01  xmlDocChild  usage object reference ClassXmlNode.
  28.         01  xmlNode      usage object reference ClassXmlNode.
  29.         01  rsaKey       usage object reference ClassRSACryptoServiceProvider.
  30.         01  signedXml    usage object reference ClassSignedXml.
  31.         01  xmlReference usage object reference ClassXmlReference.
  32.         01  emptyString  usage object reference SystemString.
  33.         01  env          usage object reference ClassXmlDsigEnvSignatureTrans.
  34.         01  xmlDigitalSignature  usage object reference ClassXmlElement.
  35.         01  xmlElement   usage object reference ClassXmlElement.
  36.  
  37.   procedure division.
  38.  
  39.   *> Cobol does not support empty strings, so this a trick
  40.     set  emptyString   to  StringEmpty of SystemString
  41.  
  42.   *> C#  CspParameters cspParams = new CspParameters();
  43.       invoke ClassCspParameters "NEW" returning cspParams
  44.  
  45.   *> C# cspParams.KeyContainerName = "XML_DSIG_RSA_KEY";
  46.      set   KeyContainer OF cspParams   to  "XML_DSIG_RSA_KEY"
  47.  
  48.   *> C# RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider(cspParams);
  49.  
  50.      invoke ClassRSACryptoServiceProvider "NEW" using cspParams returning rsaKey
  51.  
  52.   *> C# XmlDocument xmlDoc = new XmlDocument();
  53.  
  54.      invoke ClassXmlDocument "NEW" returning xmlDoc
  55.  
  56.   *> C# xmlDoc.PreserveWhitespace = true;
  57.      set  PreserveWhitespace of xmlDoc  to b"1"  
  58.  
  59.   *> C# xmlDoc.Load("test.xml");
  60.      invoke xmlDoc "Load" using "c:\test.xml"  
  61.  
  62.   *> C# SignedXml signedXml = new SignedXml(Doc);
  63.      invoke ClassSignedXml "NEW" using  xmlDoc returning signedXml  
  64.  
  65.   *> C# signedXml.SigningKey = Key; - it should be rsaKey instead of just "Key"
  66.      set  SigningKey of signedXml   to  rsaKey
  67.  
  68.   *> C# Reference reference = new Reference();
  69.      invoke ClassXmlReference "NEW" returning xmlReference  
  70.  
  71.   *> reference.Uri = "";   // !! means all document
  72.     set  uri of xmlReference    to  emptyString  
  73.  
  74.   *> C$ XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
  75.      invoke ClassXmlDsigEnvSignatureTrans "NEW" returning env  
  76.  
  77.   *> C# reference.AddTransform(env);
  78.      invoke xmlReference "AddTransform" using env
  79.  
  80.   *> C# signedXml.AddReference(reference);
  81.      invoke signedXml "AddReference" using xmlReference  
  82.  
  83.   *> signedXml.ComputeSignature()
  84.      invoke signedXml "ComputeSignature"  
  85.  
  86.   *> C# XmlElement xmlDigitalSignature = signedXml.GetXml();
  87.      invoke signedXml "GetXml" returning xmlDigitalSignature  
  88.  
  89.   *> C# Doc.DocumentElement.AppendChild(Doc.ImportNode(xmlDigitalSignature, true));
  90.      invoke xmlDoc "ImportNode" using xmlDigitalSignature, b"1" returning xmlDocChild  
  91.  
  92.     set    xmlElement   to  DocumentElement of xmlDoc  
  93.  
  94.     invoke xmlElement "AppendChild" using xmlDocChild  
  95.  
  96.   *> C# xmlDoc.Save("SignedTest.xml");
  97.      invoke xmlDoc "Save" using "c:\SignedTest.xml"    
  98.  
  99.     stop run.

Testing our app:

Código XML:
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <Cliente version="1.0">
  3.     <Nome>Elis</Nome>
  4.     <Contatos>
  5.          <Telefone>99-9999-9999</Telefone>
  6.          <eMail>[email protected]</eMail>
  7.         </Contatos>
  8. </Cliente>

After run our app:

Código XML:
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <Cliente version="1.0">
  3.     <Nome>Elis</Nome>
  4.     <Contatos>
  5.          <Telefone>99-9999-9999</Telefone>
  6.          <eMail>[email protected]</eMail>
  7.         </Contatos>
  8.         <Signature xmlns=http://www.w3.org/2000/09/xmldsig#><SignedInfo>
  9. <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
  10. <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /><Reference URI="">
  11. <Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
  12. </Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
  13. <DigestValue>y4V1upGm/awXUcAKWFAG/PSRDAU=</DigestValue></Reference></SignedInfo>
  14. <SignatureValue>CNVyQxiYBVN C0o3szSkz 65mHFZ JV7rGgTkV62NH/i8fDN1yUJyd7Zo88TH4qdc
  15. U Vc qPLSIwaHO411TgI5N vmitbodhYI4O7n8HwbDa1nTEsTeGnpsXlGXTJsTvQVUe1FpD HTsITfFmE
  16. zs9HiuN5sY3glag4EZUCEyDIk=</SignatureValue>
  17. </Signature></Cliente>



NORMAS DEL FORO - para garantizar el buen funcionamiento del Foro.
¿Te han ayudado? NO TE OLVIDES de darle a
¿Quieres dirigirte a alguien en tu post? Notifícale haciendo clic en su Nick
Kuk is offline   Responder Con Cita
  #2
Antiguo 26 de febrero de 2017, 20:48
Recato53
Patrocinador del Foro
Última Actividad 19.07.2025 12:10
Posts Posts: 79
Likes enviados Enviados: 72
Likes recibidos Recibidos: 11

Estoy intentando probar le código para firma un archivo XML y no consigo compilar el proyecto, se producen muchos errores, creo que falta algo.

Estoy muy interesado en este programa, me puedes enviar el proyecto en PowerCobol.

Muchas gracias.
Un saludo.
Recato53 is offline   Responder Con Cita
  #3
Antiguo 26 de febrero de 2017, 23:38
Kuk
Administrador
Última Actividad 19.09.2026 20:11
Posts Posts: 2.500
Likes enviados Enviados: 1037
Likes recibidos Recibidos: 1207

Recato53, este código es de NetCOBOL .NET, si te fijas está usando clases externas que corresponden con Namespaces de .NET:

Código COBOL:
  1.  repository.
  2.    class ClassCspParameters             as "System.Security.Cryptography.CspParameters"
  3.    class ClassXmlDocument               as "System.Xml.XmlDocument"
  4.    class ClassXmlNode                   as "System.Xml.XmlNode"
  5.    class ClassRSACryptoServiceProvider as "System.Security.Cryptography.RSACryptoServiceProvider"
  6.    class ClassSignedXml                 as "System.Security.Cryptography.Xml.SignedXml"
  7.    class ClassXmlReference             as "System.Security.Cryptography.Xml.Reference"
  8. ...

Eslopes, corrígeme si me estoy equivocando.



NORMAS DEL FORO - para garantizar el buen funcionamiento del Foro.
¿Te han ayudado? NO TE OLVIDES de darle a
¿Quieres dirigirte a alguien en tu post? Notifícale haciendo clic en su Nick
Kuk is offline   Responder Con Cita
  #4
Antiguo 21 de diciembre de 2017, 14:26
Eslopes
Creador de
PowerRustCOBOL
Guru de los Gurus: Por solidos y amplios conocimientos - Issue reason: Por ámplios conocimientos en la materia Concurso: Tercer puesto: Ganador/a del Tercer puesto en un concurso - Issue reason: Juego  Innovación: Por aportar innovaciones - Issue reason: Por aportar soluciones innovadoras 
Última Actividad 20.09.2026 13:24
Posts Posts: 357
Likes enviados Enviados: 29
Likes recibidos Recibidos: 157

Sim, está correto. Todavia é possível usar este código com o Power. Neste caso é necessário criar uma DLL e expor a mesma para o Power, o qual poderá chamar uma DLL .Net desde que a mesma seja devidamente registrada no Windows Registry. Google é seu melhor amigo!!!
Eslopes is offline   Responder Con Cita
Respuesta


Herramientas

Derechos de Publicación
No puedes publicar nuevos temas
No puedes publicar posts/responder
No puedes adjuntar archivos
No puedes editar tus posts

BB code is habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado

Saltar a Foro


La franja horaria es GMT +2. Ahora son las 17:09.
Powered by: vBulletin, Versión 3.8.7
Derechos de Autor ©2000 - 2026, Jelsoft Enterprises Ltd.