HMACSHA1 function using the ABL SHA1-DIGEST

Cecil

19+ years progress programming and still learning.
If you are using OpenEdge 11.7.4 you can now do this:

Code:
DEFINE VARIABLE chJSONData AS CHARACTER   NO-UNDO.
DEFINE VARIABLE chKey AS CHARACTER   NO-UNDO.
DEFINE VARIABLE lcLong AS LONGCHAR   NO-UNDO.

chJSONData = '{data:"somedatahere"}'.
chKey      = "ApplicationKey"  .

lcLong = HEX-ENCODE(MESSAGE-DIGEST("HMAC-SHA-256" , chJSONData, chKey)).

MESSAGE STRING(chLong).
 

GillesQ

New Member
I have a customer who is still running 11.5 in production so I'm stuck with the old method. I found the result of the HMAC-SHA-256 is different when using a key larger than 64 bytes. The problem comes from the correction for large keys:

Code:
    /* correction by Valery A.Eliseev */
    IF LENGTH(pcKey) > {&xiBlockSize} THEN
    DO:
        set-size(mData) = LENGTH(pcKey).
        put-string(mData, 1, LENGTH(pcKey)) = pcKey.
        // Only valid for HMAC-SHA-1 
        // rRawDataSHA = SHA1-DIGEST(mData).
        rRawDataSHA = MESSAGE-DIGEST('SHA-256', mData).
        PUT-BYTES(mKey, 1) = rRawDataSHA.
    END.
 

Cecil

19+ years progress programming and still learning.
Hi I wrote this function for a particular purpose over 15 years ago . I’m still amazed today that it’s being used.

Is it possible that you could use an alternative method like .net?

Before I wrote the function many many years ago, i used a command line utility to do the hashing, maybe something like that still exist today as alternative workaround?
 

GillesQ

New Member
I wrote this function for a particular purpose over 15 years ago . I’m still amazed today that it’s being used.
I'm glad you did that, very useful !

Is it possible that you could use an alternative method like .net?
Before I wrote the function many many years ago, i used a command line utility to do the hashing, maybe something like that still exist today as alternative workaround?
Customer is using AIX, so no .Net here. They will migrate to OE 11.7 (and then to 12) in a couple months, so this code will be replaced with the builtin version.
 
Top