*Sample Code to generate Key:
data: random type xstring, wa_bench_config type zhr_bench_config.
call method cl_sec_sxml_writer=>generate_key
exporting
algorithm = cl_sec_sxml_writer=>co_aes256_algorithm
receiving
key = random.
data(lr_conv_key) = cl_abap_conv_out_ce=>create( ).
lr_conv_key->write( data = random ).
e_key = lr_conv_key->get_buffer( ).
data: i_key_xstring type xstring, i_iv type xstring.
i_iv = '00000000000000000000000000000000'.
if i_text is not initial.
call function 'SCMS_BASE64_DECODE_STR'
exporting
input = i_text
* UNESCAPE = 'X'
importing
output = i_xstring
* EXCEPTIONS
* FAILED = 1
* OTHERS = 2
.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.
endif.
if i_xstring is not initial.
* For CL_SEC_SXML_WRITER to work with external application we need to add 16 bit
* extra padding before decryption
concatenate i_iv(16) i_xstring into i_xstring in byte mode.
try.
cl_sec_sxml_writer=>decrypt(
exporting
ciphertext = i_xstring
key = i_key_xstring
algorithm = cl_sec_sxml_writer=>co_aes256_algorithm_pem
importing
plaintext = data(lv_message_decrypted) ).
" convert xstring to string for output
cl_abap_conv_in_ce=>create( input = lv_message_decrypted )->read( importing data = e_text_dec ).
catch cx_sec_sxml_encrypt_error into data(oref). .
endtry.
endif.
data(lr_conv_sec) = cl_abap_conv_out_ce=>create( ).
lr_conv_sec->write( data = i_text ).
" encrypt using AES256
i_xstring = lr_conv_sec->get_buffer( ).
i_iv = '00000000000000000000000000000000'.
cl_sec_sxml_writer=>encrypt_iv(
exporting
plaintext = i_xstring
key = i_key_xstring
iv = i_iv
algorithm = cl_sec_sxml_writer=>co_aes256_algorithm_pem
importing
ciphertext = data(lv_message) ).
data: lr_conv type ref to cl_abap_conv_in_ce,
lr_xstring type xstring,
lr_string type string.
*Before sending encrypted information to external system, remove the extra
*16 bit padding from the xstring
lr_xstring = lv_message+16.
data: lt_data type tsfixml, l_len type i.
call function 'SCMS_BASE64_ENCODE_STR'
exporting
input = lr_xstring
importing
output = e_text_enc.
endif.
EXAMPLE:
Text: Test AES@CBC#PKCS$5
Encrypted Text : B8Q1+w5vH9jG3V/ejYg5igeGNgfX6nvqUGrDnogyDdo=
After Decryption : Test AES@CBC#PKCS$5
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 |