SAP加密解密功能设计

news2024/11/17 9:50:47

SAP加密解密功能设计

【场景】与外围系统对接时,出于信息安全等因素,经常需要对传输的信息做加密解密控制。

1. 公用类zcl_aes_utility

*----------------------------------------------------------------------*
*       CLASS ZCL_AES_UTILITY DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zcl_aes_utility DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.

*"* public components of class ZCL_AES_UTILITY
*"* do not include other source files here!!!
    CONSTANTS mc_block_length_in_bit TYPE int4 VALUE 128 ##NO_TEXT.
    CONSTANTS mc_block_length_in_byte TYPE int4 VALUE 16 ##NO_TEXT.
    CONSTANTS mc_key_length_in_bit_128 TYPE int4 VALUE 128 ##NO_TEXT.
    CONSTANTS mc_key_length_in_bit_192 TYPE int4 VALUE 192 ##NO_TEXT.
    CONSTANTS mc_key_length_in_bit_256 TYPE int4 VALUE 256 ##NO_TEXT.
    CONSTANTS mc_encryption_mode_ecb TYPE char10 VALUE 'ECB' ##NO_TEXT.
    CONSTANTS mc_encryption_mode_cbc TYPE char10 VALUE 'CBC' ##NO_TEXT.
    CONSTANTS mc_encryption_mode_pcbc TYPE char10 VALUE 'PCBC' ##NO_TEXT.
    CONSTANTS mc_encryption_mode_cfb TYPE char10 VALUE 'CFB' ##NO_TEXT.
    CONSTANTS mc_encryption_mode_ofb TYPE char10 VALUE 'OFB' ##NO_TEXT.
    CONSTANTS mc_encryption_mode_ctr TYPE char10 VALUE 'CTR' ##NO_TEXT.
    CONSTANTS mc_padding_standard_none TYPE char10 VALUE 'NONE' ##NO_TEXT.
    CONSTANTS mc_padding_standard_pkcs_7 TYPE char10 VALUE 'PKCS7' ##NO_TEXT.
    CLASS-DATA:
      mt_raw16 TYPE TABLE OF zif_aes_mode=>ty_raw16 .

    CLASS-METHODS is_valid_iv_xstring
      IMPORTING
        !i_initialization_vector TYPE xstring
      RETURNING
        VALUE(r_valid)           TYPE boole_d .
    CLASS-METHODS encrypt_xstring
      IMPORTING
        !i_key                   TYPE xstring
        !i_data                  TYPE xstring
        !i_initialization_vector TYPE xstring OPTIONAL
        !i_padding_standard      TYPE char10 OPTIONAL
        !i_encryption_mode       TYPE char10 OPTIONAL
      EXPORTING
        !e_data                  TYPE xstring .
    CLASS-METHODS decrypt_xstring
      IMPORTING
        !i_key                   TYPE xstring
        !i_data                  TYPE xstring
        !i_initialization_vector TYPE xstring OPTIONAL
        !i_padding_standard      TYPE char10 OPTIONAL
        !i_encryption_mode       TYPE char10 OPTIONAL
      EXPORTING
        !e_data                  TYPE xstring .
    CLASS-METHODS encrypt_raw16_table
      IMPORTING
        !i_key                   TYPE xstring
        !i_initialization_vector TYPE xstring OPTIONAL
        !i_encryption_mode       TYPE char10 OPTIONAL
        !i_padding_standard      TYPE char10 OPTIONAL
        !i_data_length_in_byte   TYPE int4
      EXPORTING
        !et_data                 LIKE mt_raw16
      CHANGING
        !ct_data                 LIKE mt_raw16 .
    CLASS-METHODS decrypt_raw16_table
      IMPORTING
        !i_key                   TYPE xstring
        !i_initialization_vector TYPE xstring
        !i_encryption_mode       TYPE char10
        !i_padding_standard      TYPE char10
        !it_data                 LIKE mt_raw16
      EXPORTING
        !e_data_length_in_byte   TYPE int4
        !et_data                 LIKE mt_raw16 .
    CLASS-METHODS convert_xstring_to_raw16_table
      IMPORTING
        !i_data                TYPE xstring
      EXPORTING
        !e_data_length_in_byte TYPE int4
        !et_raw16_table        LIKE mt_raw16 .
    CLASS-METHODS convert_raw16_table_to_xstring
      IMPORTING
        !i_data_length_in_byte TYPE int4
        !it_raw16_table        LIKE mt_raw16
      EXPORTING
        !e_data                TYPE xstring .
    CLASS-METHODS validate_encryption_mode
      IMPORTING
        !i_initialization_vector TYPE xstring OPTIONAL
        !i_encryption_mode       TYPE char10 OPTIONAL .
    CLASS-METHODS validate_padding_standard
      IMPORTING
        !i_padding_standard TYPE char10 OPTIONAL .
    CLASS-METHODS validate_raw16_table_size
      IMPORTING
        !i_data_length_in_byte TYPE int4
        !it_data               LIKE mt_raw16 .
    CLASS-METHODS add_padding_raw16_table
      IMPORTING
        !i_data_length_in_byte TYPE int4
        !io_padding_utility    TYPE REF TO zcl_byte_padding_utility
      CHANGING
        !ct_data               LIKE mt_raw16 .
    CLASS-METHODS remove_padding_raw16_table
      IMPORTING
        !io_padding_utility    TYPE REF TO zcl_byte_padding_utility
      EXPORTING
        !e_data_length_in_byte TYPE int4
      CHANGING
        !ct_data               LIKE mt_raw16 .

    2. 类/接口ZCL_AES_MODE_ECB

*----------------------------------------------------------------------*
*       INTERFACE ZIF_AES_MODE
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
INTERFACE zif_aes_mode
  PUBLIC .

  types: ty_raw16 type x length 16.

  CLASS-DATA:
    mt_raw16 TYPE TABLE OF ty_raw16 .

  METHODS decrypt_raw16_table
    IMPORTING
      !io_rijndael TYPE REF TO zcl_rijndael_utility
      !i_key TYPE xstring
      !i_initialization_vector TYPE xstring
      !it_data LIKE mt_raw16
    EXPORTING
      !et_data LIKE mt_raw16 .
  METHODS encrypt_raw16_table
    IMPORTING
      !io_rijndael TYPE REF TO zcl_rijndael_utility
      !i_key TYPE xstring
      !i_initialization_vector TYPE xstring
      !it_data LIKE mt_raw16
    EXPORTING
      !et_data LIKE mt_raw16 .
ENDINTERFACE.  

2. 类/接口 ZIF_AES_MODE

*----------------------------------------------------------------------*
*       INTERFACE ZIF_AES_MODE
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
INTERFACE zif_aes_mode
  PUBLIC .

  types: ty_raw16 type x length 16.

  CLASS-DATA:
    mt_raw16 TYPE TABLE OF ty_raw16 .

  METHODS decrypt_raw16_table
    IMPORTING
      !io_rijndael TYPE REF TO zcl_rijndael_utility
      !i_key TYPE xstring
      !i_initialization_vector TYPE xstring
      !it_data LIKE mt_raw16
    EXPORTING
      !et_data LIKE mt_raw16 .
  METHODS encrypt_raw16_table
    IMPORTING
      !io_rijndael TYPE REF TO zcl_rijndael_utility
      !i_key TYPE xstring
      !i_initialization_vector TYPE xstring
      !it_data LIKE mt_raw16
    EXPORTING
      !et_data LIKE mt_raw16 .
ENDINTERFACE.        

*----------------------------------------------------------------------*
*       CLASS ZCL_AES_MODE_CBC DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS zcl_aes_mode_cbc DEFINITION
  PUBLIC
  CREATE PUBLIC .

  PUBLIC SECTION.

    INTERFACES zif_aes_mode .

3. 加密方法ENCRYPT_XSTRING加密

  METHOD encrypt_xstring.
    DATA: lt_plain_raw16           LIKE mt_raw16,
          lt_cipher_raw16          LIKE mt_raw16,
          lv_plain_length_in_byte  TYPE int4,
          lv_cipher_length_in_byte TYPE int4.

    CLEAR e_data.

    convert_xstring_to_raw16_table(
      EXPORTING
        i_data      = i_data
      IMPORTING
        e_data_length_in_byte = lv_plain_length_in_byte
        et_raw16_table        = lt_plain_raw16 ).

    encrypt_raw16_table(
      EXPORTING
        i_data_length_in_byte   = lv_plain_length_in_byte
        i_encryption_mode       = i_encryption_mode
        i_initialization_vector = i_initialization_vector
        i_padding_standard      = i_padding_standard
        i_key                   = i_key
      IMPORTING
        et_data                 = lt_cipher_raw16
      CHANGING
        ct_data                 = lt_plain_raw16 ).

    lv_cipher_length_in_byte = lines( lt_cipher_raw16 ) * mc_block_length_in_byte.

    convert_raw16_table_to_xstring(
      EXPORTING
        it_raw16_table          = lt_cipher_raw16
        i_data_length_in_byte   = lv_cipher_length_in_byte
      IMPORTING
        e_data                  = e_data ).

  ENDMETHOD.                    "encrypt_xstring

METHOD:  CONVERT_XSTRING_TO_RAW16_TABLE

  METHOD convert_xstring_to_raw16_table.
    DATA: lv_input_length     TYPE int4,
          lv_number_of_blocks TYPE int4,
          lv_block_cursor     TYPE int4,
          lv_offset           TYPE int4.

    FIELD-SYMBOLS: <raw16>      TYPE zif_aes_mode=>ty_raw16.

    CLEAR et_raw16_table.

    lv_input_length = xstrlen( i_data ).
    lv_number_of_blocks = ceil( '1.0' * lv_input_length / mc_block_length_in_byte ).

    lv_block_cursor = 1.
    lv_offset = 0.
    WHILE lv_block_cursor <= lv_number_of_blocks.
      APPEND INITIAL LINE TO et_raw16_table ASSIGNING <raw16>.

      IF lv_block_cursor < lv_number_of_blocks.
        <raw16> = i_data+lv_offset(mc_block_length_in_byte).
      ELSE.
        <raw16> = i_data+lv_offset.
      ENDIF.

      lv_block_cursor = lv_block_cursor + 1.
      lv_offset = lv_offset + mc_block_length_in_byte.
    ENDWHILE.

    e_data_length_in_byte = lv_input_length.

  ENDMETHOD.                    "convert_xstring_to_raw16_table

METHOD:ENCRYPT_RAW16_TABLE

  METHOD encrypt_raw16_table.
    DATA: rijndael                TYPE REF TO zcl_rijndael_utility.
    DATA: padding_utility         TYPE REF TO zcl_byte_padding_utility.
    DATA: aes_mode                TYPE REF TO zif_aes_mode.

    CLEAR et_data.

    validate_encryption_mode(
        i_encryption_mode       = i_encryption_mode
        i_initialization_vector = i_initialization_vector ).

    validate_padding_standard( i_padding_standard ).

    validate_raw16_table_size(
        it_data                 = ct_data
        i_data_length_in_byte   = i_data_length_in_byte ).

    rijndael = get_rijndael( i_key ).
    padding_utility = get_padding_utility( i_padding_standard ).
    aes_mode = get_aes_mode( i_encryption_mode ).

    add_padding_raw16_table(
      EXPORTING
        i_data_length_in_byte   = i_data_length_in_byte
        io_padding_utility      = padding_utility
      CHANGING
        ct_data                 = ct_data ).

    aes_mode->encrypt_raw16_table(
      EXPORTING
        io_rijndael             = rijndael
        i_key                   = i_key
        i_initialization_vector = i_initialization_vector
        it_data                 = ct_data
      IMPORTING
        et_data                 = et_data ).

  ENDMETHOD.                    "encrypt_raw16_table

METHOD:CONVERT_RAW16_TABLE_TO_XSTRING

  METHOD convert_raw16_table_to_xstring.
    DATA: lv_last_line_length   TYPE int4.
    FIELD-SYMBOLS: <raw16>      TYPE zif_aes_mode=>ty_raw16.

    CLEAR e_data.

    IF i_data_length_in_byte <= 0.
      RETURN.
    ENDIF.

    lv_last_line_length = ( i_data_length_in_byte - 1 ) MOD mc_block_length_in_byte + 1.

    LOOP AT it_raw16_table ASSIGNING <raw16>.
      AT LAST.
        e_data = e_data && <raw16>(lv_last_line_length).
        EXIT.
      ENDAT.

      e_data = e_data && <raw16>.
    ENDLOOP.

  ENDMETHOD.                    "convert_raw16_table_to_xstring

4. 解密方法DECRYPT_XSTRING

  METHOD decrypt_xstring.
    DATA: lt_plain_raw16          LIKE mt_raw16,
          lt_cipher_raw16         LIKE mt_raw16,
          lv_plain_length_in_byte TYPE int4.

    CLEAR e_data.

    convert_xstring_to_raw16_table(
      EXPORTING
        i_data      = i_data
      IMPORTING
        et_raw16_table        = lt_cipher_raw16 ).

    decrypt_raw16_table(
      EXPORTING
        i_encryption_mode       = i_encryption_mode
        i_initialization_vector = i_initialization_vector
        i_padding_standard      = i_padding_standard
        i_key                   = i_key
        it_data                 = lt_cipher_raw16
      IMPORTING
        e_data_length_in_byte   = lv_plain_length_in_byte
        et_data                 = lt_plain_raw16 ).

    convert_raw16_table_to_xstring(
      EXPORTING
        it_raw16_table          = lt_plain_raw16
        i_data_length_in_byte   = lv_plain_length_in_byte
      IMPORTING
        e_data                  = e_data ).

  ENDMETHOD.                    "decrypt_xstring

method:DECRYPT_RAW16_TABLE

  METHOD decrypt_raw16_table.
    DATA: rijndael                TYPE REF TO zcl_rijndael_utility.
    DATA: padding_utility         TYPE REF TO zcl_byte_padding_utility.
    DATA: aes_mode                TYPE REF TO zif_aes_mode.

    CLEAR et_data.

    validate_encryption_mode(
        i_encryption_mode       = i_encryption_mode
        i_initialization_vector = i_initialization_vector ).

    validate_padding_standard( i_padding_standard ).

    rijndael = get_rijndael( i_key ).
    padding_utility = get_padding_utility( i_padding_standard ).
    aes_mode = get_aes_mode( i_encryption_mode ).

    aes_mode->decrypt_raw16_table(
      EXPORTING
        io_rijndael             = rijndael
        i_key                   = i_key
        i_initialization_vector = i_initialization_vector
        it_data                 = it_data
      IMPORTING
        et_data                 = et_data ).

    remove_padding_raw16_table(
      EXPORTING
        io_padding_utility      = padding_utility
      IMPORTING
        e_data_length_in_byte   = e_data_length_in_byte
      CHANGING
        ct_data                 = et_data ).

  ENDMETHOD.                    "DECRYPT_RAW16_TABLE

method: VALIDATE_ENCRYPTION_MODE 

  METHOD validate_encryption_mode.

    IF i_encryption_mode = mc_encryption_mode_cbc
        OR i_encryption_mode = mc_encryption_mode_pcbc
        OR i_encryption_mode = mc_encryption_mode_cfb
        OR i_encryption_mode = mc_encryption_mode_ofb
        OR i_encryption_mode = mc_encryption_mode_ctr.
      IF is_valid_iv_xstring( i_initialization_vector ) = abap_false.
        RAISE EXCEPTION TYPE cx_me_illegal_argument
          EXPORTING
            name  = 'I_INITIALIZATION_VECTOR'
            value = 'Incorrect Initialization Vector length'.
      ENDIF.

    ELSEIF i_encryption_mode = mc_encryption_mode_ecb
          OR i_encryption_mode IS INITIAL.
      "Nothing, default is ECB mode

    ELSE.
      RAISE EXCEPTION TYPE cx_me_illegal_argument
        EXPORTING
          name  = 'I_ENCRYPTION_MODE'
          value = 'Incorrect Encryption Mode'.

    ENDIF.

  ENDMETHOD.                    "validate_encryption_mode
  METHOD is_valid_iv_xstring.
    DATA: iv_length_in_bit   TYPE int4.

    iv_length_in_bit = xstrlen( i_initialization_vector ) * zcl_rijndael_utility=>mc_factor_bit_byte.

    IF iv_length_in_bit = mc_block_length_in_bit.
      r_valid = abap_true.
    ENDIF.

  ENDMETHOD.                    "is_valid_iv_xstring
  METHOD validate_padding_standard.

    IF  i_padding_standard IS NOT INITIAL AND
        i_padding_standard <> zcl_byte_padding_utility=>mc_padding_standard_none AND
        i_padding_standard <> zcl_byte_padding_utility=>mc_padding_standard_pkcs_5 AND
        i_padding_standard <> zcl_byte_padding_utility=>mc_padding_standard_pkcs_7.

      RAISE EXCEPTION TYPE cx_me_illegal_argument
        EXPORTING
          name  = 'I_PADDING_STANDARD'
          value = 'Unsupported padding standard'.

    ENDIF.

  ENDMETHOD.                    "validate_padding_standard

method:GET_RIJNDAEL

  METHOD get_rijndael.
    DATA: key_length_in_bit   TYPE int4.

    key_length_in_bit = xstrlen( i_key ) * zcl_rijndael_utility=>mc_factor_bit_byte.

    IF key_length_in_bit = mc_key_length_in_bit_128.
      IF mo_rijndael_128_128 IS NOT BOUND.
        CREATE OBJECT mo_rijndael_128_128
          EXPORTING
            i_key_length_in_bit   = mc_key_length_in_bit_128
            i_block_length_in_bit = mc_block_length_in_bit.
      ENDIF.

      r_rajndael = mo_rijndael_128_128.

    ELSEIF key_length_in_bit = mc_key_length_in_bit_192.
      IF mo_rijndael_128_192 IS NOT BOUND.
        CREATE OBJECT mo_rijndael_128_192
          EXPORTING
            i_key_length_in_bit   = mc_key_length_in_bit_192
            i_block_length_in_bit = mc_block_length_in_bit.
      ENDIF.

      r_rajndael = mo_rijndael_128_192.

    ELSEIF key_length_in_bit = mc_key_length_in_bit_256.
      IF mo_rijndael_128_256 IS NOT BOUND.
        CREATE OBJECT mo_rijndael_128_256
          EXPORTING
            i_key_length_in_bit   = mc_key_length_in_bit_256
            i_block_length_in_bit = mc_block_length_in_bit.
      ENDIF.

      r_rajndael = mo_rijndael_128_256.

    ELSE.
      RAISE EXCEPTION TYPE cx_me_illegal_argument
        EXPORTING
          name  = 'I_KEY'
          value = 'Incorrect key length'.
    ENDIF.

  ENDMETHOD.                    "get_rijndael

method:GET_PADDING_UTILITY

  METHOD get_padding_utility.
    CASE i_padding_standard.
      WHEN space OR zcl_byte_padding_utility=>mc_padding_standard_none.
        IF mo_padding_utility_none IS NOT BOUND.
          mo_padding_utility_none = zcl_byte_padding_utility=>get_byte_padding_utility( i_padding_standard ).
        ENDIF.
        r_padding_utility = mo_padding_utility_none.

      WHEN zcl_byte_padding_utility=>mc_padding_standard_pkcs_5.
        IF mo_padding_utility_pkcs_5 IS NOT BOUND.
          mo_padding_utility_pkcs_5 = zcl_byte_padding_utility=>get_byte_padding_utility( i_padding_standard ).
        ENDIF.
        r_padding_utility = mo_padding_utility_pkcs_5.

      WHEN zcl_byte_padding_utility=>mc_padding_standard_pkcs_7.
        IF mo_padding_utility_pkcs_7 IS NOT BOUND.
          mo_padding_utility_pkcs_7 = zcl_byte_padding_utility=>get_byte_padding_utility( i_padding_standard ).
        ENDIF.
        r_padding_utility = mo_padding_utility_pkcs_7.

    ENDCASE.
  ENDMETHOD.                    "get_padding_utility

method: GET_AES_MODE

I_ENCRYPTION_MODE    TYPE CHAR10
value( R_AES_MODE )    TYPE REF TO ZIF_AES_MODE

  METHOD get_aes_mode.
    CASE i_encryption_mode.
      WHEN space OR mc_encryption_mode_ecb.
        IF mo_aes_mode_ecb IS NOT BOUND.
          CREATE OBJECT mo_aes_mode_ecb TYPE zcl_aes_mode_ecb.
        ENDIF.
        r_aes_mode = mo_aes_mode_ecb.

      WHEN mc_encryption_mode_cbc.
        IF mo_aes_mode_cbc IS NOT BOUND.
          CREATE OBJECT mo_aes_mode_cbc TYPE zcl_aes_mode_cbc.
        ENDIF.
        r_aes_mode = mo_aes_mode_cbc.

      WHEN mc_encryption_mode_pcbc.
        IF mo_aes_mode_pcbc IS NOT BOUND.
          CREATE OBJECT mo_aes_mode_pcbc TYPE zcl_aes_mode_pcbc.
        ENDIF.
        r_aes_mode = mo_aes_mode_pcbc.

      WHEN mc_encryption_mode_cfb.
        IF mo_aes_mode_cfb IS NOT BOUND.
          CREATE OBJECT mo_aes_mode_cfb TYPE zcl_aes_mode_cfb.
        ENDIF.
        r_aes_mode = mo_aes_mode_cfb.

      WHEN mc_encryption_mode_ofb.
        IF mo_aes_mode_ofb IS NOT BOUND.
          CREATE OBJECT mo_aes_mode_ofb TYPE zcl_aes_mode_ofb.
        ENDIF.
        r_aes_mode = mo_aes_mode_ofb.

      WHEN mc_encryption_mode_ctr.
        IF mo_aes_mode_ctr IS NOT BOUND.
          CREATE OBJECT mo_aes_mode_ctr TYPE zcl_aes_mode_ctr.
        ENDIF.
        r_aes_mode = mo_aes_mode_ctr.

    ENDCASE.

  ENDMETHOD.                    "get_aes_mode

method: REMOVE_PADDING_RAW16_TABLE 

  METHOD remove_padding_raw16_table.
    DATA: lv_padding_length      TYPE int4,
          lv_last_line_number    TYPE int4,
          lv_line_before_padding TYPE xstring,
          lv_line_after_padding  TYPE xstring.

    FIELD-SYMBOLS: <raw16> TYPE zif_aes_mode=>ty_raw16.

    CLEAR e_data_length_in_byte.

    lv_last_line_number = lines( ct_data ).
    IF lv_last_line_number <= 0.
      RETURN.
    ENDIF.

    READ TABLE ct_data INDEX lv_last_line_number ASSIGNING <raw16>.
    lv_line_after_padding = <raw16>.

    io_padding_utility->remove_padding(
      EXPORTING
        i_block_length_in_byte    = mc_block_length_in_byte
        i_data                    = lv_line_after_padding
      IMPORTING
        e_padding_length_in_byte  = lv_padding_length
        e_data                    = lv_line_before_padding ).

    IF lv_line_before_padding IS INITIAL.
      DELETE ct_data INDEX lv_last_line_number.
    ELSE.
      <raw16> = lv_line_before_padding.
    ENDIF.

    e_data_length_in_byte = lv_last_line_number * mc_block_length_in_byte - lv_padding_length.

  ENDMETHOD.                    "remove_padding_raw16_table

5. 功能应用

AES加密秘钥配置

  METHOD encrypt_data.
    DATA:
      lv_xstr_out TYPE xstring,
      lv_xstr_key TYPE xstring,
      lv_key      TYPE string,
      lv_xstr_in  TYPE xstring,
      lv_input    TYPE string.

    CLEAR: ev_encrypted.

    IF iv_value IS INITIAL.
      RETURN.
    ENDIF.

    lv_input = iv_value.

    SELECT SINGLE sctky INTO lv_key FROM ztab_aes01
      WHERE bssnr = 'FI1183'
        AND isdel = abap_off.
    IF sy-subrc <> 0.
      IF sy-mandt <> '600'.
        lv_key = 'mGaDFIZTfGSgNNdj'.
      ELSE.
        RETURN.
      ENDIF.
    ENDIF.

    CALL FUNCTION 'ECATT_CONV_STRING_TO_XSTRING'
      EXPORTING
        im_string  = lv_input
      IMPORTING
        ex_xstring = lv_xstr_in.

    CALL FUNCTION 'ECATT_CONV_STRING_TO_XSTRING'
      EXPORTING
        im_string  = lv_key
      IMPORTING
        ex_xstring = lv_xstr_key.

    zcl_aes_utility=>encrypt_xstring(
      EXPORTING
        i_key                   = lv_xstr_key
        i_data                  = lv_xstr_in
        i_padding_standard      = zcl_aes_utility=>mc_padding_standard_pkcs_7
        i_encryption_mode       = zcl_aes_utility=>mc_encryption_mode_ecb
      IMPORTING
        e_data                  = lv_xstr_out
    ).

    CALL FUNCTION 'SCMS_BASE64_ENCODE_STR'
      EXPORTING
        input  = lv_xstr_out
      IMPORTING
        output = ev_encrypted.
  ENDMETHOD.
  METHOD gen_wy_attach_url.
    DATA:
      lv_yxurl       TYPE c LENGTH 1000,
      lv_token       TYPE c LENGTH 1000,
      lv_encode      TYPE savwctxt-fieldcont,
      ls_ztfi1040_07 TYPE ztfi1040_07,
      lv_token_str   TYPE string,
      lv_ts          TYPE n LENGTH 14.

    CLEAR: ev_url, es_return.

    ls_ztfi1040_07-ywdnr = iv_ywdnr.

    SELECT SINGLE ywdnr yxurl fi_type
      INTO ( ls_ztfi1040_07-ywdnr, ls_ztfi1040_07-yxurl ,ls_ztfi1040_07-fi_type )
      FROM ztfi1040_07
      WHERE ywdnr = ls_ztfi1040_07-ywdnr.
    IF  sy-subrc             <> 0       OR
         ls_ztfi1040_07-yxurl IS INITIAL OR
         ls_ztfi1040_07-yxurl =  space.
*          es_return-type    = 'E'.
*          es_return-message = '无附件信息'.
*          RETURN.
      SELECT SINGLE ywdnr yxurl fi_type
      INTO ( ls_ztfi1040_07-ywdnr, ls_ztfi1040_07-yxurl,ls_ztfi1040_07-fi_type )
      FROM ztfi1040_01
      WHERE ywdnr = ls_ztfi1040_07-ywdnr.
      IF   sy-subrc             <> 0  OR ls_ztfi1040_07-yxurl IS INITIAL OR
            ls_ztfi1040_07-yxurl =  space.
        es_return-type    = 'E'.
        es_return-message = '无附件信息'.
        RETURN.
      ENDIF.
    ENDIF.

    lv_ts        = sy-datum && sy-uzeit.
    lv_token_str = lv_ts && |^_^| && ls_ztfi1040_07-yxurl.

    me->encrypt_data(
      EXPORTING
        iv_value     = lv_token_str
      IMPORTING
        ev_encrypted = lv_token_str
    ).
    IF lv_token_str IS INITIAL.
      es_return-type    = 'E'.
      es_return-message = '加密失败'.
      RETURN.
    ENDIF.
    lv_encode = lv_token_str.
    CALL FUNCTION 'WWW_URLENCODE'
      EXPORTING
        value         = lv_encode
      IMPORTING
        value_encoded = lv_token.

    lv_encode = ls_ztfi1040_07-yxurl.
    CLEAR lv_yxurl.
    CALL FUNCTION 'WWW_URLENCODE'
      EXPORTING
        value         = lv_encode
      IMPORTING
        value_encoded = lv_yxurl.
    CASE sy-mandt.
      WHEN 600.
        IF ls_ztfi1040_07-fi_type EQ 'WD1' OR ls_ztfi1040_07-fi_type EQ 'WD2' OR ls_ztfi1040_07-fi_type EQ 'WD3'.   
          ev_url = 'http://bf.xxxxservice.com/hscs/ap/land/rec/files/view'.                                          
        ELSE.                                                                                                         
        ENDIF.                                                                                                        

      WHEN OTHERS.
        ev_url =  'http://10.0.xxx/hscs/ap/land/time/files/view'.
    ENDCASE.

    ev_url            = ev_url && '?key=' && lv_yxurl && '&token=' && lv_token.
    es_return-type    = 'S'.
    es_return-message = '附件页面URL获取成功'.
  ENDMETHOD.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2119821.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Ubuntu 22.04 安装增强功能失败

安装的时候&#xff0c;总是失败&#xff0c;然后根据提示查看 log 猜测可能需要安装g12 ubuntu22.04.2 目前(until 23.6.25) gcc 的默认版本是 11.3.0, 有些 c 的特性无法享用.Launchpad toolchain test buildsLanchpad toolchain build 将 Lanchpad 上的 PPA 加入到 apt 搜…

用Python包加速你的视频剪辑:Tailor工具全解析

Tailor是一款视频智能裁剪、视频生成和视频优化的视频剪辑工具。目前的目标是通过人工智能技术减少视频剪辑的繁琐操作&#xff0c;让普通人也能简单实现专业剪辑人的水准&#xff01;长远目标是让视频剪辑实现真正的AIGC&#xff01; 当然&#xff0c;这是一份Python包的列表…

分组注解和自定义注解及分页查询

自定义注解的使用步骤 案例&#xff1a; 此时state需要进行的校验使用普通方式无法满足&#xff0c;需要我们根据需求进行自定义注解 创建一个注解 Documented//元注解 Retention(RetentionPolicy.RUNTIME)//元注解 Constraint(validatedBy {StateValidation.class}//指定提供…

DPDK基础入门(七):网卡性能优化

DPDK的轮询模式 运行在操作系统内核态的网卡驱动程序基本都是基于异步中断处理模式&#xff0c;而DPDK采用了轮询或者轮询混杂中断的模式来进行收包和发包。 任何包进入到网卡&#xff0c;网卡硬件会进行必要的检查、计算、解析和过滤等&#xff0c;最终包会进入物理端口的某…

最高1000万 各地模型和算法备案补贴政策一览

最高1000万 各地模型和算法备案补贴政策一览 2024年7月31日&#xff0c;成都市的人工智能产业再度引起关注。通过国家大模型备案的三家企业——海艺互娱、晓多科技和明途科技&#xff0c;获得了成都市经信局市新经济委的百万奖励。这一奖励源自成都发布的《成都市进一步促进人工…

手把手带你拿捏指针(1)

文章目录 一、内存和地址1.内存编号、地址和指针的关系2.对于编址的理解 二、指针变量和地址1.取地址操作符&2.指针变量3.解引用操作符(*)4.指针变量的大小 三、指针变量类型的意义1.指针解引用2.指针-整数3.void*指针 四、const修饰指针1.const修饰变量2.const修饰指针变量…

避障小车—51单片机

一、小车底盘组装 根据视频的安装步骤安装 二、 电机模块开发 2.1 L9110s概述 接通VCC&#xff0c;GND 模块电源指示灯亮&#xff0c; 以下资料来源官方&#xff0c;但是不对&#xff0c;根据下节课实际调试 IA1输入高电平&#xff0c;IA1输入低电平&#xff0c;【OA1 OB1…

【项目二】C++高性能服务器开发——日志系统(终章)

感谢sylar&#xff0c;感谢开源笔记的所有人~ 知识点备忘录switch结合宏定义简化获取时间戳获取行号获取线程ID 知识点备忘录 上一篇适配器后得到的输出是下面这样&#xff0c;在main函数中定义了需要的一切&#xff0c;和项目所需要的还相差很远&#xff0c;比如日志级别需要…

通过AI来创建一个_____html css网页制作成品 例子演示

使用AI 输入创建一个 html css网页制作成品 例 然后出来 好的&#xff0c;我将为您创建一个简单的HTML和CSS网页制作的示例。这个示例将包括基本的布局、文本样式和一些内联的CSS样式。 { "name": "dalle", "description": "A simple exa…

价值流思维:全面提升业务效率与企业竞争力的核心方法论

价值流驱动的企业架构转型 在数字化浪潮的推动下&#xff0c;企业面临前所未有的竞争压力和业务复杂性。如何在动态市场环境中保持竞争优势&#xff0c;已经成为企业管理者亟待解决的问题。《价值流指南》由The Open Group发布的企业数字化转型专业参考指南&#xff0c;系统化…

为啥有人累死累活,还是穷?

咱们今天不聊怎么发财&#xff0c;来聊聊“为啥有人穷”。一说穷&#xff0c;大家第一反应就是钱不够花&#xff0c;但少有人想到&#xff0c;穷还可能是精神上的、思想上的、道德上的。表面看缺钱&#xff0c;背后往往有更深的原因。 记得《我不是药神》里那假药贩子张长林吗&…

【Redis】Redis 典型应用 - 缓存 (Cache) 原理与策略

目录 Redis 典型应⽤ - 缓存 (cache)什么是缓存使⽤ Redis 作为缓存缓存的更新策略1)定期⽣成2)实时生成 缓存预热&#xff0c;缓存穿透&#xff0c;缓存雪崩 和 缓存击穿关于缓存预热 (Cache preheating)什么是缓存预热 关于缓存穿透 (Cache penetration)什么是缓存穿透为何产…

Kafka API操作

文章目录 1、 Kafka 基础API1_Topic基本操作 DML管理2_生产者3_消费者 sub/assign4_自定义分区策略5_序列化6_拦截器 2、Kafka API高级特性1_Offset自动控制2_Acks & Retries3_幂等性4_事务控制1、生产者事务Only2、消费者&生产者事务3、测试需要的三个消费者案例属性 …

【Rust】Mdbook插件开发和分享——多图浏览和多语言代码

mdbook-image-slider 受DevExpress文档多图浏览的启发&#xff0c;我开发这个插件&#xff0c;在查看多个图片和图片的描述的时候非常方便 项目地址&#xff1a;https://github.com/VinciYan/mdbook-image-slider.git 特点 鼠标置于图片查看区域时显示切换图片按钮鼠标点击图…

chapter14-集合——(collection)——day17

目录 499-集合介绍 500-集合体系图 背下来 501-Collection方法 502-迭代器遍历 itit&#xff08;迭代器快捷键&#xff09;&#xff08;Ctrlj&#xff09; 503-集合增强for 快捷I 504-测试题 499-集合介绍 500-集合体系图 背下来 单列集合 双列集合&#xff08;键值对&am…

如何根据屋顶的面积和形状设计光伏板的排布?

首先我们得了解项目的具体的情况数据&#xff1a; 测量屋顶尺寸&#xff1a;准确测量屋顶的长、宽等数据&#xff0c;了解其面积大小 分析屋顶形状&#xff1a;观察屋顶是平顶、坡顶还是其他形状&#xff0c;这会影响排布方式。 支架的排布&#xff1a;要保证发电量的同时&a…

序列标注任务

序列标注任务 1.序列标注任务2.序列标注--中文分词2.1数据标注方法一2.2数据标注方法二 3.序列标注--NER3.1序列标注--CRF3.2篱笆墙解码3.3beam search3.4维特比解码3.5效率对比3.6评价指标 4.基于规则-NER4.1序列标注--文本加标点4.2序列标注--句子级别分类4.3实体抽取问题4.4…

田纳西州橡树岭全球最快的超级计算机名为Frontier

每周跟踪AI热点新闻动向和震撼发展 想要探索生成式人工智能的前沿进展吗&#xff1f;订阅我们的简报&#xff0c;深入解析最新的技术突破、实际应用案例和未来的趋势。与全球数同行一同&#xff0c;从行业内部的深度分析和实用指南中受益。不要错过这个机会&#xff0c;成为AI领…

【VuePress 个人博客搭建】

个人博客搭建免服务器 一、安装 VuePress1、创建文件夹并进入该目录2、初始化项目3、安装VuePress4、在 package.json 中修改 scripts5、创建目录和配置文件6、创建第一篇文档Hello VuePress7、 运行项目二、部署1、新建github 仓库2、在 config.js 添加 base 路径配置:3、创建…

使用 Parallel 类进行多线程编码(下)

2.Parallel.ForEach() 的使用 从 ForEach() 这个名字可以看出该方法是用来遍历泛型集合的&#xff0c;新建一个 ASP.NET Core Web应用的项目&#xff0c;如下&#xff1a; 在 Index.cshtml.cs 文件中增加一个 UserInfo.cs 的类&#xff0c;代码如下&#xff1a; public class U…