<?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 Encryption issue using class CL_SEC_SXML_WRITER in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/encryption-issue-using-class-cl-sec-sxml-writer/m-p/13968915#M2038172</link>
    <description>&lt;P&gt;We have to encrypt 1 field for sending to external API with AES256 algorithm with a provided AES256 key (from external system).&amp;nbsp; I used method&amp;nbsp;CL_SEC_SXML_WRITER=&amp;gt;ENCRYPT for the encryption with algorithm parameter&amp;nbsp;&lt;!--   StartFragment    --&gt;&lt;SPAN&gt;cl_sec_sxml_writer&lt;SPAN class=""&gt;=&amp;gt;&lt;/SPAN&gt;co_aes256_algorithm but I don't get the expected result.&amp;nbsp; I verify the result thru online encryption tools, and various tools results in the same encrypted value but not from&amp;nbsp;CL_SEC_SXML_WRITER=&amp;gt;ENCRYPT.&amp;nbsp; I verified the hex values of the data and key and they are correct and consistent.&amp;nbsp; Every execution of the code, results to a different encrypted value.&amp;nbsp; The receiving system has also confirmed that they can not decrypt the passed value, same when I decrypt it thru online tools.&amp;nbsp; How can I make this method work?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Here is my code:&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;DATA lv_aeskey TYPE string. "32 character key
    DATA lv_key TYPE xstring.
    DATA lv_data TYPE string.
    DATA lv_data_xstr TYPE string.
    DATA lv_msg TYPE xstring.

    data(lr_conv_key) = cl_abap_conv_out_ce=&amp;gt;create( ).
    lr_conv_key-&amp;gt;write( data = lv_aeskey ).
    lv_key = lr_conv_key-&amp;gt;get_buffer( ).

    "Converting the data - From string format to xstring. You can use any other method or function module which converts the string to xstring format
    data(lr_conv_data) = cl_abap_conv_out_ce=&amp;gt;create( ).
    lr_conv_data-&amp;gt;write( data = lv_data ).
    lv_data_xstr = lr_conv_data-&amp;gt;get_buffer( ).

    "Encrypt the data using the key
    cl_sec_sxml_writer=&amp;gt;encrypt(
      EXPORTING
        plaintext =  lv_data_xstr
        key       =  lv_key
        algorithm =  cl_sec_sxml_writer=&amp;gt;co_aes256_algorithm
      IMPORTING
        ciphertext = lv_msg ).&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Dec 2024 04:48:58 GMT</pubDate>
    <dc:creator>giancarla_aguilar</dc:creator>
    <dc:date>2024-12-20T04:48:58Z</dc:date>
    <item>
      <title>Encryption issue using class CL_SEC_SXML_WRITER</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/encryption-issue-using-class-cl-sec-sxml-writer/m-p/13968915#M2038172</link>
      <description>&lt;P&gt;We have to encrypt 1 field for sending to external API with AES256 algorithm with a provided AES256 key (from external system).&amp;nbsp; I used method&amp;nbsp;CL_SEC_SXML_WRITER=&amp;gt;ENCRYPT for the encryption with algorithm parameter&amp;nbsp;&lt;!--   StartFragment    --&gt;&lt;SPAN&gt;cl_sec_sxml_writer&lt;SPAN class=""&gt;=&amp;gt;&lt;/SPAN&gt;co_aes256_algorithm but I don't get the expected result.&amp;nbsp; I verify the result thru online encryption tools, and various tools results in the same encrypted value but not from&amp;nbsp;CL_SEC_SXML_WRITER=&amp;gt;ENCRYPT.&amp;nbsp; I verified the hex values of the data and key and they are correct and consistent.&amp;nbsp; Every execution of the code, results to a different encrypted value.&amp;nbsp; The receiving system has also confirmed that they can not decrypt the passed value, same when I decrypt it thru online tools.&amp;nbsp; How can I make this method work?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Here is my code:&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;DATA lv_aeskey TYPE string. "32 character key
    DATA lv_key TYPE xstring.
    DATA lv_data TYPE string.
    DATA lv_data_xstr TYPE string.
    DATA lv_msg TYPE xstring.

    data(lr_conv_key) = cl_abap_conv_out_ce=&amp;gt;create( ).
    lr_conv_key-&amp;gt;write( data = lv_aeskey ).
    lv_key = lr_conv_key-&amp;gt;get_buffer( ).

    "Converting the data - From string format to xstring. You can use any other method or function module which converts the string to xstring format
    data(lr_conv_data) = cl_abap_conv_out_ce=&amp;gt;create( ).
    lr_conv_data-&amp;gt;write( data = lv_data ).
    lv_data_xstr = lr_conv_data-&amp;gt;get_buffer( ).

    "Encrypt the data using the key
    cl_sec_sxml_writer=&amp;gt;encrypt(
      EXPORTING
        plaintext =  lv_data_xstr
        key       =  lv_key
        algorithm =  cl_sec_sxml_writer=&amp;gt;co_aes256_algorithm
      IMPORTING
        ciphertext = lv_msg ).&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2024 04:48:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/encryption-issue-using-class-cl-sec-sxml-writer/m-p/13968915#M2038172</guid>
      <dc:creator>giancarla_aguilar</dc:creator>
      <dc:date>2024-12-20T04:48:58Z</dc:date>
    </item>
  </channel>
</rss>

