<?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 JWT With RSA256 Encryption ABAP Stack in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/jwt-with-rsa256-encryption-abap-stack/m-p/13655833#M2027468</link>
    <description>&lt;P&gt;Hello.&lt;/P&gt;&lt;P&gt;I'm trying to create a JWT like on the website&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://jwt.io/" target="_blank" rel="nofollow noopener noreferrer"&gt;https://jwt.io/&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;The signature section uses the SHA256withRSA / RSA256 algorithm with the private key provided.&lt;/P&gt;&lt;P&gt;How to make SHA256withRSA / RSA256 encryption with abap stack.&lt;/P&gt;&lt;P&gt;I have tried using Class cl_abap_hmac=&amp;gt;calculate_hmac_for_char and cl_abap_message_digest=&amp;gt;calculate_hash_for_char but it doesn't work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Has anyone an idea how to achieve this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;LI-PRODUCT title="ABAP Development" id="833755570260738661924709785639136"&gt;&lt;/LI-PRODUCT&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Apr 2024 12:31:30 GMT</pubDate>
    <dc:creator>FI3</dc:creator>
    <dc:date>2024-04-02T12:31:30Z</dc:date>
    <item>
      <title>JWT With RSA256 Encryption ABAP Stack</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/jwt-with-rsa256-encryption-abap-stack/m-p/13655833#M2027468</link>
      <description>&lt;P&gt;Hello.&lt;/P&gt;&lt;P&gt;I'm trying to create a JWT like on the website&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://jwt.io/" target="_blank" rel="nofollow noopener noreferrer"&gt;https://jwt.io/&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;The signature section uses the SHA256withRSA / RSA256 algorithm with the private key provided.&lt;/P&gt;&lt;P&gt;How to make SHA256withRSA / RSA256 encryption with abap stack.&lt;/P&gt;&lt;P&gt;I have tried using Class cl_abap_hmac=&amp;gt;calculate_hmac_for_char and cl_abap_message_digest=&amp;gt;calculate_hash_for_char but it doesn't work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Has anyone an idea how to achieve this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;LI-PRODUCT title="ABAP Development" id="833755570260738661924709785639136"&gt;&lt;/LI-PRODUCT&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 12:31:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/jwt-with-rsa256-encryption-abap-stack/m-p/13655833#M2027468</guid>
      <dc:creator>FI3</dc:creator>
      <dc:date>2024-04-02T12:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: JWT With RSA256 Encryption ABAP Stack</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/jwt-with-rsa256-encryption-abap-stack/m-p/13658377#M2027495</link>
      <description>&lt;P&gt;Hello FI3,&lt;/P&gt;&lt;P&gt;Could you please check this code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;PRIVATE SECTION.
    TYPES:
      BEGIN OF ty_jwt_header,
        alg TYPE string,
        typ TYPE string,
      END OF ty_jwt_header .

    TYPES:
      BEGIN OF ty_jwt_payload,
        secret TYPE string, " private key
        iat    TYPE i, "Issued At
        exp    TYPE i, "Expiration Time
      END OF ty_jwt_payload .&lt;/LI-CODE&gt;&lt;LI-CODE lang="abap"&gt;METHOD generate_jwttoken.
    TRY.
        DATA(ls_header) = VALUE ty_jwt_header( alg = me-&amp;gt;t_params[ name = c_alg ]-value  "HS256
                                               typ = me-&amp;gt;t_params[ name = c_typ ]-value ).  "JWT

        DATA(lv_json_header) = /ui2/cl_json=&amp;gt;serialize( data        = ls_header
                                                        compress    = abap_on
                                                        pretty_name = /ui2/cl_json=&amp;gt;pretty_mode-low_case ).
        DATA(lv_b64_header) = cl_http_utility=&amp;gt;if_http_utility~encode_base64( lv_json_header ).

        DATA(lv_currentts) = zcl_bc_util=&amp;gt;generate_timestamp( iv_tzone = 'TURKEY' ).
        DATA(lv_plus5min)  = lv_currentts + 300.
        DATA(ls_payload)   = VALUE ty_jwt_payload( secret = me-&amp;gt;t_params[ name = c_private ]-value
                                                   iat    = lv_currentts
                                                   exp    = lv_plus5min ).

        DATA(lv_json_payload) = /ui2/cl_json=&amp;gt;serialize( data        = ls_payload
                                                         compress    = abap_on
                                                         pretty_name = /ui2/cl_json=&amp;gt;pretty_mode-low_case ).
        DATA(lv_b64_payload) = cl_http_utility=&amp;gt;if_http_utility~encode_base64( lv_json_payload ).
        DATA(lv_xpublic)     = zcl_bc_util=&amp;gt;conv_string_to_xstring( CONV string( me-&amp;gt;t_params[ name = c_public ]-value ) ).
        DATA(lv_data)        = lv_b64_header &amp;amp;&amp;amp; '.' &amp;amp;&amp;amp; lv_b64_payload.

        cl_abap_hmac=&amp;gt;calculate_hmac_for_char( EXPORTING if_algorithm     = CONV string( me-&amp;gt;t_params[ name = c_algorithm ]-value )  "SHA256
                                                         if_key           = lv_xpublic
                                                         if_data          = lv_data
                                               IMPORTING ef_hmacb64string = DATA(lv_b64_hmac) ).

        DATA(lv_off) = strlen( lv_b64_hmac ) - 1.
        lv_b64_hmac  = lv_b64_hmac(lv_off).

        REPLACE ALL OCCURRENCES OF: '/' IN lv_b64_hmac WITH '_',
                                    '+' IN lv_b64_hmac WITH '-'.

        me-&amp;gt;v_token  = lv_data &amp;amp;&amp;amp; '.' &amp;amp;&amp;amp; lv_b64_hmac.

      CATCH cx_abap_message_digest INTO DATA(lx_hmac). " Exception Class for Message Digest
        RAISE EXCEPTION TYPE zcx_kw
          EXPORTING
            textid = lx_hmac-&amp;gt;if_t100_message~t100key.

*      CATCH zcx_bc_util INTO DATA(lx_bc). " 
*        RAISE EXCEPTION TYPE zcx_kw
*          EXPORTING
*            textid = lx_bc-&amp;gt;if_t100_message~t100key.

    ENDTRY.
ENDMETHOD.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;METHOD generate_timestamp.
*   IMPORTING !iv_tzone      TYPE tznzone DEFAULT 'UTC'
*   RETURNING VALUE(rv_secs) TYPE tzntstmpl
*   RAISING   zcx_bc_util.

    DATA ts1 TYPE c LENGTH 20.

    GET TIME STAMP FIELD DATA(ts).
    CONVERT TIME STAMP ts TIME ZONE iv_tzone INTO DATE DATA(dt) TIME DATA(tm).
    ts1 = dt &amp;amp;&amp;amp; tm.

    DATA(ts2) = CONV tzntstmpl( '19700101000000' ).

    TRY.
        " Time Interval in Seconds
        rv_secs = CONV int4( cl_abap_tstmp=&amp;gt;subtract( EXPORTING tstmp1 = CONV tzntstmpl( ts1 )
                                                                tstmp2 = ts2 ) ).

      CATCH cx_parameter_invalid_range INTO DATA(lx_range). " Parameter with invalid value range
        "DATA(ls_t100) = set_message_from_obj( lx_range ).

      CATCH cx_parameter_invalid_type INTO DATA(lx_type).  " Parameter with Invalid Type
        "ls_t100 = set_message_from_obj( lx_type ).

    ENDTRY.

    CHECK ls_t100 IS NOT INITIAL.
*    RAISE EXCEPTION TYPE zcx_bc_util
*      EXPORTING
*        textid = ls_t100.

ENDMETHOD.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;METHOD conv_string_to_xstring.
    DATA: ls_t100 TYPE scx_t100key.

    CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
      EXPORTING
        text     = iv_str
        mimetype = 'charset=utf-8'
        encoding = '4110'
      IMPORTING
        buffer   = rv_xstr
      EXCEPTIONS
        failed   = 1
        OTHERS   = 2.

    CHECK sy-subrc &amp;lt;&amp;gt; 0.

*    ls_t100 = set_messagge_from_sy( ).

*    RAISE EXCEPTION TYPE zcx_bc_util
*      EXPORTING
*        textid = ls_t100.

ENDMETHOD.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;P&gt;Caner.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2024 07:27:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/jwt-with-rsa256-encryption-abap-stack/m-p/13658377#M2027495</guid>
      <dc:creator>caner_genis</dc:creator>
      <dc:date>2024-04-04T07:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: JWT With RSA256 Encryption ABAP Stack</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/jwt-with-rsa256-encryption-abap-stack/m-p/13658691#M2027500</link>
      <description>&lt;P&gt;Hello Caner.&lt;/P&gt;&lt;P&gt;Thankyou for the code. really appreciate it.&lt;/P&gt;&lt;P&gt;But for the requierement, i need to encrypt the signature with RS256 Algorithm instead of SHA256.&lt;/P&gt;&lt;P&gt;if we try at jwt.io we can choose RS256 in the dropdown list.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="FI3_1-1712223080691.png" style="width: 400px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/91099i68174B550D77D888/image-size/medium?v=v2&amp;amp;px=400" role="button" title="FI3_1-1712223080691.png" alt="FI3_1-1712223080691.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;the output will be different beetween RS256 and SHA256.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;i tried with&amp;nbsp;&lt;SPAN&gt;cl_abap_hmac=&amp;gt;calculate_hmac_for_char with exporting if_algoritm = 'RSA256' then error occured.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;is the RS256 algorithm not supported in SAP ? &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regrads.&lt;BR /&gt;FI3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2024 09:34:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/jwt-with-rsa256-encryption-abap-stack/m-p/13658691#M2027500</guid>
      <dc:creator>FI3</dc:creator>
      <dc:date>2024-04-04T09:34:36Z</dc:date>
    </item>
  </channel>
</rss>

