在ABAP中加密字符串并在JavaScript中解密 [英] Encrypt string in ABAP and decrypt in JavaScript

查看:85
本文介绍了在ABAP中加密字符串并在JavaScript中解密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ABAP类,该类将字符串编码为qr码并将此代码作为电子邮件发送.稍后,该代码将由基于JavaScript的SAPUI5应用解码.

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.

我不希望每个人都可以使用一些基本的条形码扫描器应用程序解码该二维码后面的字符串.这就是为什么我要寻找一些关于在ABAP中加密字符串并使用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.

感谢您的提示和想法!

推荐答案

ABAP cl_hard_wired_encryptor 中有一个类可以完全满足您的要求.它使用base64加密,因此可以在JS中轻松解密.

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.

这是示例代码:

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.

这篇关于在ABAP中加密字符串并在JavaScript中解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆