matinal:ABAP 字符串的 Base64 加密和解密

2023-10-14 14:05:32 浏览数 (1)

base64加密:

代码语言:javascript复制
FORM encode_base64  USING    p_business  “字符串string
                    CHANGING p_base64.

  DATA l_xstring TYPE xstring.
  CHECK p_business IS NOT INITIAL.

  CALL METHOD cl_http_utility=>encode_utf8
    EXPORTING
      unencoded = p_business
    RECEIVING
      encoded   = l_xstring.

  CALL METHOD cl_http_utility=>encode_x_base64  
    EXPORTING
      unencoded = l_xstring
    RECEIVING
      encoded   = p_base64.
ENDFORM. 

base64解密:

代码语言:javascript复制
FORM decoding_base64 CHANGING p_business TYPE string.

  DATA l_xstring TYPE xstring.
  CALL METHOD cl_http_utility=>if_http_utility~decode_x_base64
    EXPORTING
      encoded = p_business
    RECEIVING
      decoded = l_xstring.

  CLEAR p_business.
  CALL METHOD cl_http_utility=>if_http_utility~decode_utf8
    EXPORTING
      encoded   = l_xstring
    RECEIVING
      unencoded = p_business.

ENDFORM. 

0 人点赞