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

查看:37
本文介绍了在 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天全站免登陆