assinar xml

Boa dia a todos, por favor estou tentando fazer uma assinatura digital em um XML, e esta dando super certo com a ajuda do exemples que Chris Glazier e Altair Borges me enviaram, porem esta assinando com o algoritimo RSA-SHA1 mas eu preciso assinar com algoritimo RSA-SHA256, eu achei um exemplo que eu acredite que seja o que eu preciso conforme esta abaixo em C#, mas não estou conseguindo converter o Visual COBOL for Visual Studio, se alguém conseguir me ajudar ficarei muito agradecido.

 

atenciosamente

 

Renato Soares Vieira

 

using System; using System.Security.Cryptography; class RSASample { static void Main() { try { //Create a new instance of RSACryptoServiceProvider. using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { //The hash to sign. byte[] hash; using (SHA256 sha256 = SHA256.Create()) { byte[] data = new byte[] { 59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 224, 93, 25, 41, 100, 197, 213, 134, 130, 135 }; hash = sha256.ComputeHash(data); } //Create an RSASignatureFormatter object and pass it the //RSACryptoServiceProvider to transfer the key information. RSAPKCS1SignatureFormatter RSAFormatter = new RSAPKCS1SignatureFormatter(rsa); //Set the hash algorithm to SHA256. RSAFormatter.SetHashAlgorithm("SHA256"); //Create a signature for HashValue and return it. byte[] SignedHash = RSAFormatter.CreateSignature(hash); } } catch (CryptographicException e) { Console.WriteLine(e.Message); } } }

  • Open up the Project Properties page and look on the Application tab. This is where you set the .NET Framework version. The list of supported Frameworks can change depending on which Visual Studio version you are using. I am using VS2017.

    The actual assemblies need to be added as References in the References folder. If you expand this folder and select one of the assemblies you will see its properties if your property window is displayed.
  • Sorry but I did not understand this part "The actual assemblies need to be added as References in the References folder. If you expand this folder and select one of the assemblies you will see its properties if your property window is displayed."
    I have to go to "project", "Add Reference", then open a screen, what do I need to do?

    thank you
  • The example code that you provided makes use of .NET classes that are in non-default .NET assemblies.  In order to make these classes available you must reference the assemblies.

    RSAPKCS1SHA256SignatureDescription is a class whose full name is System.Deployment.Internal.CodeSigning.RSAPKCS1SHA256SignatureDescription.

    At the top of the class I set the following directive:

    $set ilusing"System.Deployment.Internal.CodeSigning"

    This allows us to reference the class as RSAPKCS1SHA256SignatureDescription instead of specifying the full namespace.

    The RSAPKCS1SHA256SignatureDescription class is found in the .NET Assembly System.Deployment.dll. In order to find the class you have to add a reference to this assembly in your project. You can do this by right-clicking on the References folder in the project and selecting Add Reference and then navigate to System.Deployment in the list of .NET assemblies and select it and click on OK. It will then show up in the list as shown below:

  • Good afternoon, i´m completes the Project(in annex) and is working perfectly, but when compiling it is generating an executable .exe, I need to be generated .dll so I can call this routine from another program, how should I proceed to solve this.
    thank you

    RTP_2D00_SGN1.txt

  • Open up the Project Properties page and on the Application tab change the Output type from Console Application to Class Library. Then it will generate a .dll.
  • Hello Mr. Glazier, I have already done this, but I do not even get into the routines, because neither the "Stop" that I put in the beginning does not process, and also not of the error, I am using the attached example.
    Thank you

    LALA.txt

  • What error are you receiving on the call statement, a COBOL RTS 173?

    Are you stepping thru the code in the debugger?

    If the calling program is in a different project than the called program then you need to add a reference to the project containing the called program in the References folder of the project containing the calling program.

    What is the project name of the project containing the called program, is it RTP-SGN1?

    I suggest you take a look at the tutorial here:

  • Hello, it does not return any error, it simply does nothing, I only have this project of this routines I did to sign the xml, the calling program has no project, I just call the new routine by the command "call", the calling program does part of a system and is written in cobol and compiled by visual cobol for visual studio 3.0. It was a system in netExpress 3.1 that we recompiled in visual cobol for visual studio through command. cbllink -d -s -g xxx.cbl

  • What you appear to be trying to do is call a managed code .dll from a native code executable using the COBOL CALL statement. This will not work. If you compile the calling program as managed code then you can use the CALL statement to call a managed code .dll.

    In order to call a managed code .dll from a native code executable you need to use CCW or COM Callable Wrapper, which means that you Register a COBOL class for use with COM Interop and then you can instantiate it and invoke its methods using the COM support in the native COBOL libraries. (OLE).

    This is covered in the docs here:

    There is also a KB article and demo here:

  • Good morning Mr. Glazier, thank you very much for the help that worked perfectly with your tips.
    But I need to tease you a little bit with two things.
    This is working perfectly on my machine, which is of unvoltage, but how should I proceed in the client, being that on my machine when compiling it records an item in the windows registry, but on the client I do not know how we should proceed;
    another bestowal would be, these routines attached when I send the XML to sign, it shows the screen for me to choose the certificate, but I would need to do this only in the first XML, and the next one would be the same certificate, without the need to choose the certificate again , because several XMLs with the same certificate are signed, without the need to be choosing the certificate all the time, have that possibility?
    thank you

    8816.RTP_2D00_SGN1.txt