Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Encryption issue using class CL_SEC_SXML_WRITER

giancarla_aguilar
Participant
0 Likes
1,199

We have to encrypt 1 field for sending to external API with AES256 algorithm with a provided AES256 key (from external system).  I used method CL_SEC_SXML_WRITER=>ENCRYPT for the encryption with algorithm parameter cl_sec_sxml_writer=>co_aes256_algorithm but I don't get the expected result.  I verify the result thru online encryption tools, and various tools results in the same encrypted value but not from CL_SEC_SXML_WRITER=>ENCRYPT.  I verified the hex values of the data and key and they are correct and consistent.  Every execution of the code, results to a different encrypted value.  The receiving system has also confirmed that they can not decrypt the passed value, same when I decrypt it thru online tools.  How can I make this method work?

Here is my code: 

 

 

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=>create( ).
    lr_conv_key->write( data = lv_aeskey ).
    lv_key = lr_conv_key->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=>create( ).
    lr_conv_data->write( data = lv_data ).
    lv_data_xstr = lr_conv_data->get_buffer( ).

    "Encrypt the data using the key
    cl_sec_sxml_writer=>encrypt(
      EXPORTING
        plaintext =  lv_data_xstr
        key       =  lv_key
        algorithm =  cl_sec_sxml_writer=>co_aes256_algorithm
      IMPORTING
        ciphertext = lv_msg ).

 

 

0 REPLIES 0