ABAP 加密解密程序

更多内容关注公众号:SAP Technical 

各位可以关注我的公众号:SAP Technical

用于对字符串的加密和解密:

DATA: o_encryptor        TYPE REF TO cl_hard_wired_encryptor,
     o_cx_encrypt_error TYPE REF TO cx_encrypt_error.
DATA: v_ac_string  TYPE string VALUE 'RICK',
      v_ac_xstring TYPE xstring,
      v_en_string  TYPE string,
      v_en_xstring TYPE xstring,
      v_de_string  TYPE string,
      v_de_xstring TYPE string,
      v_error_msg  TYPE string.

START-OF-SELECTION.
* Create object for Encryption
  CREATE OBJECT o_encryptor.
* *&---------------------------------------------------------------------*
* Encryption - String to String
*&---------------------------------------------------------------------*
  WRITE / 'Encryption - String to String'.
  TRY.
      CALL METHOD o_encryptor->encrypt_string2string
        EXPORTING
          the_string = v_ac_string
        RECEIVING
          result     = v_en_string.
    CATCH cx_encrypt_error INTO o_cx_encrypt_error.
      CALL METHOD o_cx_encrypt_error->if_message~get_text
        RECEIVING
          result = v_error_msg.
      MESSAGE v_error_msg TYPE 'E'.
  ENDTRY.
  WRITE:/ 'Actual String: ', v_ac_string.
  WRITE:/ 'Encrypted String: ', v_en_string.
  SKIP.
*   *&---------------------------------------------------------------------*
* Decryption - String to String
*&---------------------------------------------------------------------*
  WRITE / 'Decryption - String to String'.
  TRY.
      CALL METHOD o_encryptor->decrypt_string2string
        EXPORTING
          the_string = v_en_string
        RECEIVING
          result     = v_de_string.
    CATCH cx_encrypt_error INTO o_cx_encrypt_error.
      CALL METHOD o_cx_encrypt_error->if_message~get_text
        RECEIVING
          result = v_error_msg.
      MESSAGE v_error_msg TYPE 'E'.
  ENDTRY.
  WRITE:/ 'Encrypted String: ', v_en_string.
  WRITE:/ 'Decrypted String: ', v_de_string.
  SKIP.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值