<?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>Question Re: ABAP string to SHA256 different to SAPUI5/Javascript in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955865#M4494239</link>
    <description>&lt;P&gt;The use of Javascript in ABAP is depreciated since many releases now (see also &lt;A href="https://help.sap.com/viewer/fe1d31bb6c551014b75bc66f0328fefe/7.02.19/en-US/808676416e805958e10000000a1550b0.html"&gt;https://help.sap.com/viewer/fe1d31bb6c551014b75bc66f0328fefe/7.02.19/en-US/808676416e805958e10000000a1550b0.html&lt;/A&gt; )&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jul 2019 12:18:13 GMT</pubDate>
    <dc:creator>UweFetzer_se38</dc:creator>
    <dc:date>2019-07-16T12:18:13Z</dc:date>
    <item>
      <title>ABAP string to SHA256 different to SAPUI5/Javascript</title>
      <link>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaq-p/11955863</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
  &lt;P&gt;Currently on my SAPUI5 project, I am creating a HMAC encoded string with this line of code;&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;var secretKey = CryptoJS.enc.Hex.parse('SECRETKEY'); //USING THE CRYPTOJS LIBRARY!
var hash = CryptoJS.HmacSHA256('abc', secretKey);
hashInBase64 = CryptoJS.enc.Base64.stringify(hash);&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;I am using the CryptoJS library to execute this code in UI5.&lt;/P&gt;
  &lt;P&gt;However the problem is that I am receiving the wrong HMAC encoded string when I want to do the same in ABAP. After testing a few times, it seems like the encoding (in abap) is wrong before the HMAC is calculated.&lt;BR /&gt;&lt;BR /&gt;Is there a function module that does 'CryptoJS.enc.Hex.parse()' - after googling what it does it interprets the parameter as encoded and converts it into a word array.&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;DATA:
      lv_sign_key_x                TYPE xstring,
      lv_hmac_result               TYPE string.

DATA(lv_binary_secret) = cl_abap_hmac=&amp;gt;string_to_xstring('SECRETKEY').

    cl_abap_hmac=&amp;gt;calculate_hmac_for_char(
      EXPORTING
        if_algorithm           = 'SHA256'           "Hash Algorithm
        if_key                 = lv_binary_secret   "HMAC Key
        if_data                = 'abc'   "Data
      IMPORTING
        ef_hmacb64string       = lv_hmac_result  "HMAC value as base64-encoded string
    ).

&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 11:02:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaq-p/11955863</guid>
      <dc:creator>former_member595185</dc:creator>
      <dc:date>2019-07-16T11:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP string to SHA256 different to SAPUI5/Javascript</title>
      <link>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955864#M4494238</link>
      <description>&lt;P&gt;You can write your javascript code too within ABAP. Have you tried that?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 11:38:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955864#M4494238</guid>
      <dc:creator>rudramani</dc:creator>
      <dc:date>2019-07-16T11:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP string to SHA256 different to SAPUI5/Javascript</title>
      <link>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955865#M4494239</link>
      <description>&lt;P&gt;The use of Javascript in ABAP is depreciated since many releases now (see also &lt;A href="https://help.sap.com/viewer/fe1d31bb6c551014b75bc66f0328fefe/7.02.19/en-US/808676416e805958e10000000a1550b0.html"&gt;https://help.sap.com/viewer/fe1d31bb6c551014b75bc66f0328fefe/7.02.19/en-US/808676416e805958e10000000a1550b0.html&lt;/A&gt; )&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 12:18:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955865#M4494239</guid>
      <dc:creator>UweFetzer_se38</dc:creator>
      <dc:date>2019-07-16T12:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP string to SHA256 different to SAPUI5/Javascript</title>
      <link>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955866#M4494240</link>
      <description>&lt;P&gt;Hi, Sunil,&lt;/P&gt;&lt;P&gt;If string is already hex-encoded, you can do a direct conversion:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA lv_binary_secret TYPE xstring.
DATA lv_input TYPE string VALUE 'EFBBBF'.
 
"only uppercase, translate to upper case if needed
lv_binary_secret = lv_input.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jul 2019 13:01:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955866#M4494240</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-07-16T13:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP string to SHA256 different to SAPUI5/Javascript</title>
      <link>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955867#M4494241</link>
      <description>&lt;P&gt;Hi Victor, The problem is that it needs to be hex encoded the same as the javascript version which is why they are bringing back two different output values. &lt;/P&gt;&lt;P&gt;Using 'SECRETKEY' as the key and 'abc' as the data...&lt;BR /&gt; &lt;BR /&gt;Javascript is giving me 'eZdbNMwgWKOANEiozokNG2FGfzI7Yy/B8IQKXr3+krY=' whilst the ABAP code is giving me '9dyEZn5G+uiRwsNqgY5S6k9/gmCheFNF4vFa5qBKK1w='&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 13:17:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955867#M4494241</guid>
      <dc:creator>former_member595185</dc:creator>
      <dc:date>2019-07-16T13:17:10Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP string to SHA256 different to SAPUI5/Javascript</title>
      <link>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955868#M4494242</link>
      <description>&lt;P&gt;I just need to know how to do the hex-encode. - Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 13:25:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955868#M4494242</guid>
      <dc:creator>former_member595185</dc:creator>
      <dc:date>2019-07-16T13:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP string to SHA256 different to SAPUI5/Javascript</title>
      <link>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955869#M4494243</link>
      <description>&lt;P&gt;In this case are you sure about this line in your JS code?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;var secretKey = CryptoJS.enc.Hex.parse('SECRETKEY');//USING THE CRYPTOJS LIBRARY!&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Method CryptoJS.enc.Hex.parse parses the already Hex-encoded string and converts it into string.&lt;/P&gt;&lt;P&gt;So if you want string from Hex, you use it and if you want hex-encoding from string then you use Hex.stringify.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;var words = CryptoJS.enc.Hex.parse("48656c6c6f2c20576f726c6421");
var hex = CryptoJS.enc.Hex.stringify(words);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So I am a bit confused here.&lt;/P&gt;&lt;P&gt;What is a value returned by this code? I assume null.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;var secretKey = CryptoJS.enc.Hex.parse('SECRETKEY');//USING THE CRYPTOJS LIBRARY!&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Check CryptoJS docs:&lt;/P&gt;&lt;P&gt;&lt;A href="https://cryptojs.gitbook.io/docs/"&gt;https://cryptojs.gitbook.io/docs/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Viktor&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 13:41:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955869#M4494243</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-07-16T13:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP string to SHA256 different to SAPUI5/Javascript</title>
      <link>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955870#M4494244</link>
      <description>&lt;P&gt;Sorry if it may seem confusing to you. not sure if 'SECRETKEY' is confusing you, I only used that word as I don't want to share the actual key I'll use '48656c6c6f2c20576f726c6421' as the key I am parsing for now.. The code in Javascript is perfectly correct and I need the ABAP to perform the same way/same results.&lt;BR /&gt;&lt;BR /&gt;In Javascript I am parsing the hex which comes back with a word array using this line of code &lt;/P&gt;&lt;P&gt;var words = CryptoJS.enc.Hex.parse("48656c6c6f2c20576f726c6421");&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;words: Array(4)
&lt;OL&gt;&lt;LI&gt;0: 1214606444&lt;/LI&gt;&lt;LI&gt;1: 1865162839&lt;/LI&gt;&lt;LI&gt;2: 1869769828&lt;/LI&gt;&lt;LI&gt;3: 553648128&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;BR /&gt;I then use the word array to be placed in var hash = CryptoJS.HmacSHA256('abc', wordArray); and then converted into Base64&lt;/P&gt;&lt;P&gt;This is all correct and the documentation is in this page - &lt;A href="https://docs.adyen.com/classic-integration/hosted-payment-pages/hmac-signature-calculation/"&gt;https://docs.adyen.com/classic-integration/hosted-payment-pages/hmac-signature-calculation/&lt;/A&gt; which is what I have done in Javascript and have tested that it works. The javascript is completely fine. I just need a solution in ABAP. &lt;BR /&gt;&lt;BR /&gt;However, I want to do the same thing in ABAP... The ABAP is returning a completely different encode &lt;/P&gt;&lt;P&gt;DATA(lv_binary_secret)= cl_abap_hmac=&amp;gt;string_to_xstring('48656c6c6f2c20576f726c6421').&lt;/P&gt;&lt;P&gt;Relating to the link I have provided above on step 4, Do you know how to hex encode my key in ABAP?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 14:07:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955870#M4494244</guid>
      <dc:creator>former_member595185</dc:creator>
      <dc:date>2019-07-16T14:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP string to SHA256 different to SAPUI5/Javascript</title>
      <link>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955871#M4494245</link>
      <description>&lt;P&gt;In this case the following should work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;    data lv_binary_secret type xstring.
    data lv_string type string value '48656c6c6f2c20576f726c6421'.
    translate lv_string to upper case.
    lv_binary_secret = lv_string.


    cl_abap_hmac=&amp;gt;calculate_hmac_for_char(
      EXPORTING
        if_algorithm           = 'SHA256'           "Hash Algorithm
        if_key                 = lv_binary_secret   "HMAC Key
        if_data                = 'abc'   "Data
      IMPORTING
        ef_hmacb64string       = data(lv_hmac_result)  "HMAC value as base64-encoded string
    ).
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jul 2019 14:27:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955871#M4494245</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-07-16T14:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP string to SHA256 different to SAPUI5/Javascript</title>
      <link>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955872#M4494246</link>
      <description>&lt;P&gt;Working as intended. Thanks a lot Viktor.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 14:34:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/abap-string-to-sha256-different-to-sapui5-javascript/qaa-p/11955872#M4494246</guid>
      <dc:creator>former_member595185</dc:creator>
      <dc:date>2019-07-16T14:34:23Z</dc:date>
    </item>
  </channel>
</rss>

