博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

CL_HARD_WIRED_ENCRYPTOR -- Encrypt and Decrypt

Posted on 2010-08-11 19:04  雷雷  阅读(548)  评论(0编辑  收藏  举报

 

*&---------------------------------------------------------------------*
*& Report  ZLEIY_ABAP_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZLEIY_ABAP_TEST.
DATA: ENCRYPTOR TYPE REF TO CL_HARD_WIRED_ENCRYPTOR,
      CX_ERROR TYPE REF TO CX_ENCRYPT_ERROR.
DATA: STRING TYPE STRING VALUE 'Welcome to SAP family',
      XSTRING TYPE XSTRING,
      V_MSG TYPE STRING,
      V_DESTRING TYPE STRING,
      V_ENSTRING TYPE STRING.
START-OF-SELECTION.
CREATE OBJECT ENCRYPTOR.
TRY.
  CALL METHOD ENCRYPTOR->ENCRYPT_STRING2STRING
  EXPORTING
    THE_STRING = STRING
  RECEIVING
  RESULT = V_ENSTRING.
CATCH  CX_ENCRYPT_ERROR INTO CX_ERROR.
  CALL METHOD CX_ERROR->IF_MESSAGE~GET_TEXT
  RECEIVING
  RESULT = V_MSG.
  MESSAGE V_MSG TYPE 'E'.
  ENDTRY.
  WRITE: V_ENSTRING.
  SKIP.
  TRY.
    CALL METHOD ENCRYPTOR->DECRYPT_STRING2STRING
    EXPORTING
      THE_STRING = V_ENSTRING
      RECEIVING
      RESULT =  V_DESTRING.
    CATCH CX_ENCRYPT_ERROR INTO CX_ERROR.
      CALL METHOD CX_ERROR->IF_MESSAGE~GET_TEXT
      RECEIVING
      RESULT = V_MSG.
      MESSAGE V_MSG TYPE 'E'.
      ENDTRY.
      WRITE:  V_DESTRING.
      SKIP.

 

PS:这种加密解密安全新不高哦,别人可以用ABAP反解密。