ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Generating HMAC signature with Newline Character

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generating HMAC signature with Newline Character

    Hi,

    I'm trying to create a String for a HMAC signature in RPGLE.

    Code PHP:

    function signRequest($method, $uri, $body, $timestamp, $secretKey)
    {
    $string = implode("\n", [ $method, $uri, $body, $timestamp, ]);
    return hash_hmac('sha256', $string, $secretKey);
    }

    $method = "POST";
    $uri = "https://www.real.de/api/v1/units/";
    $body = "";
    $timestamp = 1411055926;
    $secretKey = "a7d0cb1da1ddbc86c96ee5fedd341b7d8ebfbb2f5c83c fe09 09f4e57f05dd403";


    expected HMAC = 75312eabe66e4b9e74552a5e8959456d69cfa52a7cae904909 3aede4bcdf71e7

    Code RPGLE:

    yLf = x'25';

    yString = %trim(yMethod)
    + yLf
    + %trim(yUrl)
    + yLf
    + %trim(yBody)
    + yLf
    + %trim(yTima);

    qdcxlate(yLen:yString:'QTCPASC');

    // + logic for HMAC


    I'm guessing the yLf variable is wrong.
    I've tested this with a string without Newlines and the right HMAC was generated.

    Reference for the API:



    Any suggestions what the String has to look like?
    Last edited by hohdini; March 28, 2019, 10:38 AM.
Working...
X