Sha256 Hashes in COBOL

Here’s the translation of the SHA256 Hashes example from Go to COBOL, formatted in Markdown suitable for Hugo:

SHA256 hashes are frequently used to compute short identities for binary or text blobs. For example, TLS/SSL certificates use SHA256 to compute a certificate’s signature. Here’s how to compute SHA256 hashes in COBOL.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. SHA256-HASHES.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-STRING PIC X(20) VALUE 'sha256 this string'.
       01 WS-HASH PIC X(64).
       PROCEDURE DIVISION.
           CALL 'SHA256' USING WS-STRING WS-HASH
           DISPLAY WS-STRING
           DISPLAY WS-HASH
           STOP RUN.

In COBOL, we don’t have built-in cryptographic functions like in more modern languages. Instead, we would typically call an external library or subroutine to perform the SHA256 hash calculation. In this example, we’re assuming there’s a subroutine named ‘SHA256’ that we can call.

We start by defining our input string and a variable to hold the resulting hash.

The CALL statement is used to invoke the external SHA256 subroutine, passing it our input string and the variable to store the result.

Finally, we display both the original string and the resulting hash.

To run the program, you would compile it and then execute the resulting program:

$ cobc -x sha256-hashes.cob
$ ./sha256-hashes
sha256 this string
1af1dfa857bf1d8814fe1af8983c18080019922e557f15a8a...

Note that the actual output would depend on the implementation of the SHA256 subroutine.

It’s important to remember that if you need cryptographically secure hashes, you should carefully research hash strength and use well-tested, secure implementations.

In COBOL, for cryptographic operations, it’s common to use external libraries or system calls, as the language itself doesn’t provide built-in cryptographic functions. The exact method would depend on your COBOL environment and available libraries.