base64 HMAC Generation

Andy Whitcombe

New Member
Hi All,

Having an issue with the above.

I can generate, against a worked example, the output using .net in a few lines.

However I believe I may also need a OpenEdge solution, which is not giving me what I need.

Some test code attached, anyone see anything obvious? I've not done much with HMAC previously; I am hoping its a case of not seeing the wood for the trees

Using SHA256 as the hash algorithm.

Thanks in Advance
Andy
 

Attachments

  • hmac_1.p
    1.7 KB · Views: 7
the 2 following lines give the same result:
MyHashCode = MESSAGE-DIGEST("SHA-256", "Hello World", "simplesecret"). /* Returns a raw */
MyHashCode = MESSAGE-DIGEST("SHA-256", "Hello Worldsimplesecret"). /* Returns a raw */
i.e. el "hask key" is concatenated after the input text.

MESSAGE-DIGEST is not computing a HMAC as far as I can see.
 

Andy Whitcombe

New Member
Thanks @Jean-Christophe Cardot

Tweaked...
MyHashCode = MESSAGE-DIGEST("HMAC-SHA-256", "Hello World","simplesecret").

which gives
ASSIGN
MyHashCode = MESSAGE-DIGEST("HMAC-SHA-256", "Hello World","simplesecret"). /* Returns a raw */
vChar = HEX-ENCODE(MyHashCode).

MESSAGE
"MyHashCode " STRING(MyHashCode) SKIP(2)
"Hex Encoded" vChar SKIP(2)
"Base 64 Encode Of The Above Hash" SKIP
STRING(BASE64-ENCODE(MyHashCode))
VIEW-AS ALERT-BOX.

Works !!!
 

Rob Fitzpatrick

ProgressTalk.com Sponsor
It is important to know your OpenEdge release. HMAC is implemented natively as of 11.7.4.

This works for me:
Code:
define variable hashAlgorithm as character no-undo.  
define variable plainText     as character no-undo.  
define variable hashKey       as character no-undo.  
define variable keyedHash     as raw       no-undo.  
define variable base64Hash    as character no-undo. 

assign 
  hashAlgorithm = 'HMAC-SHA-256'  
  plainText     = 'Hello World'
  hashKey       = 'simplesecret'  
  keyedHash     = message-digest( hashAlgorithm, plainText, hashKey ) 
  base64Hash    = base64-encode( keyedHash ). 

display
  "hash algorithm : " hashAlgorithm format 'x(12)' skip
  "plaintext      : " plainText     format 'x(11)' skip
  "hash key       : " hashKey       format 'x(12)' skip
  "BASE64-encoded : " base64Hash    format 'x(44)' skip
  "expected result:  ePyqvVQ4FVjXwnxxncMi0vhdciBh3y7dEZAa28s6XqE="
 with no-labels.

Output:
Code:
hash algorithm :  HMAC-SHA-256                                
plaintext      :  Hello World                                 
hash key       :  simplesecret                                
BASE64 encoded :  ePyqvVQ4FVjXwnxxncMi0vhdciBh3y7dEZAa28s6XqE=
expected result:  ePyqvVQ4FVjXwnxxncMi0vhdciBh3y7dEZAa28s6XqE=
 
Top