Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

algorithm - Encrypt string in ABAP and decrypt in JavaScript

I have an ABAP class which encodes a string as qr code and sends this code as email. At a later point, the code will be decoded by a SAPUI5 app based on JavaScript.

I don't want that everyone can decode the string behind that qr code with some basic barcode scanner app. That's why I'm looking for some ideas for encrypting the string in ABAP and decrypting it with JavaScript. Maybe also with a simple algorithm? It's just that the string should not give usable information to someone who decodes the qr code by himself.

Thank you for your hints and ideas!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is the class in ABAP cl_hard_wired_encryptor that does exactly what you want. It uses base64 encryption so will be easily decryptable in JS.

Here is the sample code:

DATA: input_string  TYPE string VALUE `This is the house that Jack built`.

TRY.
    DATA(encrypted_string) = NEW cl_hard_wired_encryptor( )->encrypt_string2string( the_string = input_string ).
  CATCH cx_encrypt_error.
ENDTRY.

IF sy-subrc EQ 0.
  cl_demo_output=>begin_section( `Initial` ).
  cl_demo_output=>write_text( input_string ).
  cl_demo_output=>begin_section( `Encrypted` ).
  cl_demo_output=>write_text( encrypted_string ).
ELSE.
  cl_demo_output=>display( 'Error while encryption' ).
ENDIF.

TRY.
    DATA(reverted_string) = NEW cl_hard_wired_encryptor( )->decrypt_string2string( the_string = encrypted_string ).
  CATCH cx_encrypt_error.
ENDTRY.

IF sy-subrc EQ 0.
  cl_demo_output=>begin_section( `Decrypted` ).
  cl_demo_output=>write_text( reverted_string ).
  cl_demo_output=>display( ).
ELSE.
  cl_demo_output=>display( 'Error while decryption' ).
ENDIF.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...