<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic HMAC implementation in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/hmac-implementation/m-p/1913558#M380109</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to ask, if somebody already implemented HMAC algorithm with ABAP.&lt;/P&gt;&lt;P&gt;(http://tools.ietf.org/html/rfc2104#section-3). I need to calculate the HMAC-SHA1 hash code for authentification purposes.&lt;/P&gt;&lt;P&gt;thanks,&lt;/P&gt;&lt;P&gt;martin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 06 Feb 2007 10:46:10 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-02-06T10:46:10Z</dc:date>
    <item>
      <title>HMAC implementation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/hmac-implementation/m-p/1913558#M380109</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to ask, if somebody already implemented HMAC algorithm with ABAP.&lt;/P&gt;&lt;P&gt;(http://tools.ietf.org/html/rfc2104#section-3). I need to calculate the HMAC-SHA1 hash code for authentification purposes.&lt;/P&gt;&lt;P&gt;thanks,&lt;/P&gt;&lt;P&gt;martin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Feb 2007 10:46:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/hmac-implementation/m-p/1913558#M380109</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-02-06T10:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: HMAC implementation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/hmac-implementation/m-p/1913559#M380110</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My solution of HMAC implementation:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;FUNCTION Z_CALCULATE_HMAC .
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(IV_HASH_ALG) TYPE  HASHALG 
*"     REFERENCE(IV_MESSAGE) TYPE  XSTRING
*"     REFERENCE(IV_KEY) TYPE  XSTRING
*"  EXPORTING
*"     REFERENCE(EV_HASH) TYPE  HASH160
*"----------------------------------------------------------------------

* H(K XOR opad, H(K XOR ipad, text))
* B = 64 bytes

  DATA: ipad_x TYPE xstring,
        opad_x TYPE xstring,
        key_x  TYPE xstring,
        x1     TYPE x,
        x2     TYPE x,
        x3     TYPE x,
        length_key     TYPE i,
        chars_appended TYPE i,
        xor1           TYPE xstring,
        xor2           TYPE xstring,
        ev_hash_x      TYPE hash160x.

* -- index 0. - ipad, opad
* ipad = the byte 0x36 repeated B times
* opad = the byte 0x5C repeated B times.
  x1 = '36'.
  x2 = '5C'.
  x3 = '00'.
  DO 64 TIMES.
    CONCATENATE ipad_x x1  INTO ipad_x IN BYTE MODE.
    CONCATENATE opad_x x2  INTO opad_x IN BYTE MODE.
  ENDDO.

* -- index 1. - extend key to 64 bytes
* append zeros to the end of K to create a B byte string
* (e.g., if K is of length 20 bytes and B=64, then K will be appended with 44 zero bytes 0x00)
* KEY is already sended in HEX format
  key_x = iv_key.
  length_key = XSTRLEN( key_x ).

  chars_appended = 64 - length_key.
  IF chars_appended &amp;gt; 0 .
    DO chars_appended TIMES.
      CONCATENATE  key_x x3 INTO key_x IN BYTE MODE.
    ENDDO.
  ENDIF.

* -- index 2. - first calculation = Key XOR ipad
* XOR (bitwise exclusive-OR) the B byte string computed in step (1) with ipad
  xor1 = key_x BIT-XOR ipad_x.

* -- index 3.
* append the stream of data 'text' to the B byte string resulting from step (2)
* message is sended already in HEX format
*  iv_message_x = iv_message.
  CONCATENATE xor1 iv_message INTO xor1 IN BYTE MODE.

* -- index 4.
* apply H to the stream generated in step (3)
  CALL FUNCTION 'CALCULATE_HASH_FOR_RAW'
    EXPORTING
      alg  = iv_hash_alg
      data = xor1
*      length = 20
    IMPORTING
      hashx = ev_hash_x.

* -- index 5.
* XOR (bitwise exclusive-OR) the B byte string computed in step (1) with opad
  xor2 = key_x BIT-XOR opad_x.

* -- index 6.
* append the H result from step (4) to the B byte string resulting from step (5)
*  iv_message_x = ev_hash_x.
  CONCATENATE xor2 ev_hash_x INTO xor2 IN BYTE MODE.

* -- index 7.
* apply H to the stream generated in step (6) and output the result
  CALL FUNCTION 'CALCULATE_HASH_FOR_RAW'
    EXPORTING
      alg  = iv_hash_alg
      data = xor2
    IMPORTING
      hash = ev_hash.

ENDFUNCTION.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Usage: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CALL FUNCTION 'Z_TFM_CALCULATE_HMAC'
  EXPORTING
    iv_hash_alg       = 'SHA1'
    iv_message        = '4D415254494E' "MARTIN
    iv_key            = '42524154'      "BRAT
 IMPORTING
   EV_HASH           = LV_HASH          .&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;martin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Feb 2007 12:01:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/hmac-implementation/m-p/1913559#M380110</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-02-06T12:01:35Z</dc:date>
    </item>
    <item>
      <title>Re: HMAC implementation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/hmac-implementation/m-p/1913560#M380111</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I solved it already.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Feb 2007 07:49:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/hmac-implementation/m-p/1913560#M380111</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-02-09T07:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: HMAC implementation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/hmac-implementation/m-p/1913561#M380112</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Martin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to use your function module but it's not giving the result that the vendor is expecting. We have a similiar requirement of generating trusted key based on shared secret key and user id parameter. The sample trusted key 4c076e4be0de707193002f8ec723909c generated from shared key 'secret' and parameter 'user_IDJSMITH' is not the same that i m getting from ur FM. Can you please advice.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards...&lt;/P&gt;&lt;P&gt;Vinay&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Oct 2007 23:12:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/hmac-implementation/m-p/1913561#M380112</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-10-03T23:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: HMAC implementation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/hmac-implementation/m-p/1913562#M380113</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The ABAP function modules CALCULATE_HMAC_FOR_CHAR and CALCULATE_HMAC_FOR_RAW are part of the standard shipment (SAP_BASIS) as of  NetWeaver 7.1 - it was also downported to NetWeaver 7.0 Enhancement Pack 1 (see [SAP Note 1133249|https://service.sap.com/sap/support/notes/1133249]). Downports to older releases are not planned.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Wolfgang&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Sep 2008 16:45:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/hmac-implementation/m-p/1913562#M380113</guid>
      <dc:creator>Wolfgang_Janzen</dc:creator>
      <dc:date>2008-09-23T16:45:21Z</dc:date>
    </item>
  </channel>
</rss>

