首页 > 其他分享 >ABAP-AES加密解密

ABAP-AES加密解密

时间:2023-09-22 15:16:06浏览次数:51  
标签:AES encrypt string TYPE 解密 lv ABAP key xstring

  1 REPORT ytestdzp.
  2 
  3 FORM b .
  4 
  5   DATA:lv_encrypt TYPE string.     "加密前的string类型
  6   DATA:lv_encrypt_x TYPE xstring.  "加密前的xstring类型
  7 
  8   DATA:lv_encrypt_after TYPE string.    "加密后的string类型
  9   DATA:lv_encrypt_after_x TYPE xstring. "加密后的xstring类型
 10 
 11   DATA:lv_key TYPE string VALUE 'y5red17ocg5voImq', "key  密钥
 12        lv_iv  TYPE string VALUE '0000000000000000'. "iv   向量
 13 
 14   DATA : lv_key_x TYPE xstring.
 15   DATA : lv_iv_x  TYPE xstring.
 16 
 17   lv_encrypt = '5d1ceafcbd05470ca2fe969bed2e6151'.  "加密前的数据
 18 
 19   "string --> xstring
 20   CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
 21     EXPORTING
 22       text   = lv_key
 23     IMPORTING
 24       buffer = lv_key_x
 25     EXCEPTIONS
 26       failed = 1.
 27 
 28   "string --> xstring
 29   CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
 30     EXPORTING
 31       text   = lv_iv
 32     IMPORTING
 33       buffer = lv_iv_x
 34     EXCEPTIONS
 35       failed = 1.
 36 
 37   "string --> xstring
 38   CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
 39     EXPORTING
 40       text   = lv_encrypt
 41     IMPORTING
 42       buffer = lv_encrypt_x
 43     EXCEPTIONS
 44       failed = 1.
 45 
 46   " encrypt using AES256
 47   zcl_aes_utility=>encrypt_xstring(
 48     EXPORTING
 49       i_key                   = lv_key_x
 50       i_data                  = lv_encrypt_x
 51       i_initialization_vector = lv_iv_x
 52       i_padding_standard      = zcl_byte_padding_utility=>mc_padding_standard_pkcs_7 "字节填充模式
 53       i_encryption_mode       = zcl_aes_utility=>mc_encryption_mode_cbc
 54     IMPORTING
 55       e_data                  = lv_encrypt_after_x
 56   ).
 57 
 58   WRITE:'加密前:', lv_encrypt.
 59 
 60   CALL FUNCTION 'SCMS_BASE64_ENCODE_STR'
 61     EXPORTING
 62       input  = lv_encrypt_after_x
 63     IMPORTING
 64       output = lv_encrypt_after.
 65 
 66   WRITE:/ '加密后:', lv_encrypt_after.
 67 
 68 ENDFORM .
 69 
 70 FORM a .
 71 
 72   DATA:lv_decrypt   TYPE string,      "解密前的string类型
 73        lv_decrypt_x TYPE xstring.     "解密前的xstring类型
 74 
 75   DATA:lv_decrypt_after   TYPE string,   "解密后的string类型
 76        lv_decrypt_after_x TYPE xstring.  "解密后的xstring类型
 77 
 78   DATA:lv_key TYPE string VALUE 'IGcHiC4QUCXUlOx0', "key 设置对称算法的密钥
 79        lv_iv  TYPE string VALUE '0000000000000000'. "iv  设置对称算法的初始化向量
 80 
 81   DATA lv_key_x TYPE xstring .
 82   DATA lv_iv_x  TYPE xstring .
 83 
 84 
 85   lv_decrypt = 'GQ3225d7mwmj3pbHoBRsL5piGEdiYWy9pB9YwpkLkNdKMuPOd5etReMf3hgES0zdCxGsHoOjCnPLru BgeXPz1tLEXGlp3' &&
 86   'q+Xk2K3Re+PMMs+qK1RAmpJpLB5w2pKMhqTKXeh2nKlGFgyHn6tgjRiAzwTM0nWM' &&
 87   'cYFoDJZPw6kJOHLEF40zv6FSfnk7NvFrG44TdF/B/NAR4FGOKC+AmJhtYxUnXlvkt3wDxqGjHML3//b B1xLWmluBEANj5NXveq+'.
 88 
 89   " base64 --> xstring
 90   CALL FUNCTION 'SSFC_BASE64_DECODE'
 91     EXPORTING
 92       b64data                  = lv_decrypt
 93     IMPORTING
 94       bindata                  = lv_decrypt_x
 95     EXCEPTIONS
 96       ssf_krn_error            = 1
 97       ssf_krn_noop             = 2
 98       ssf_krn_nomemory         = 3
 99       ssf_krn_opinv            = 4
100       ssf_krn_input_data_error = 5
101       ssf_krn_invalid_par      = 6
102       ssf_krn_invalid_parlen   = 7.
103 
104   "string --> xstring
105   CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
106     EXPORTING
107       text   = lv_key
108     IMPORTING
109       buffer = lv_key_x
110     EXCEPTIONS
111       failed = 1.
112 
113   "string --> xstring
114   CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
115     EXPORTING
116       text   = lv_iv
117     IMPORTING
118       buffer = lv_iv_x
119     EXCEPTIONS
120       failed = 1.
121 
122   " AES解密
123   zcl_aes_utility=>decrypt_xstring(
124   EXPORTING
125     i_key                   = lv_key_x
126     i_data                  = lv_decrypt_x
127     i_initialization_vector = lv_iv_x
128     i_encryption_mode       = zcl_aes_utility=>mc_encryption_mode_cbc
129     i_padding_standard = zcl_byte_padding_utility=>mc_padding_standard_pkcs_7  "字节填充模式
130   IMPORTING
131     e_data                  = lv_decrypt_after_x ).
132 
133   WRITE: / '解密前:' , lv_decrypt.
134 
135   "Xstring --> string
136   lv_decrypt_after = cl_abap_codepage=>convert_from(
137   EXPORTING
138     source = lv_decrypt_after_x
139   ).
140 
141   WRITE: / '解密后:' , lv_decrypt_after.
142 
143 ENDFORM .

使用前需要用ABAPGIT导入加密解密的类

点击下载

标签:AES,encrypt,string,TYPE,解密,lv,ABAP,key,xstring
From: https://www.cnblogs.com/TigerMan/p/17722397.html

相关文章

  • ABAP-知识文件下载
    AES加密解密类https://files.cnblogs.com/files/blogs/720530/AES-master.zip?t=1661221651&download=true接口日志程序https://files.cnblogs.com/files/blogs/720530/ZABAP_FM_LOGGER_20220712_235637.zip?t=1661221659&download=truecodesoft打印插件https://files......
  • atob btoa 加解密
    atob(arg)对arg进行解密atob(str)对str进行加密1、兼容性:2、注意:我这次加密的时id字符串,其中只包含字母和数字;加密方法中的参数,只能包含:数字,大小写字母,应文标点符号,具体字符集是:latin1字符集;可自行百度查看其涵盖哪些字符;如果str中包含中文,中文字符等不能识别的,就会......
  • ABAP-直接取表获取特性值
    1SELECTausp~objek,2cabn~atnam,3cabn~atfor,"数据类型4cabn~msehi,"单位5cabn~atint,"间隔值6ausp~atwrt,"char特性值7ausp~atflv,"num特性值从8ausp~atflb"num间隔特性值......
  • ABAP-ITS声音配置
    1.系统有标准的声音,可以直接复制 2.创建HTML文件1`if((~messageline!="")&&(~itsmobilemsgsound=="1")||(~currdynpro.messagesound!=""))2if(~messagetype=="S"||~currdynpro.messagesound==&quo......
  • 携程ASE加密解密 java python
    java代码packagecom.example.trip_vip;importcom.alibaba.fastjson.JSON;importcom.alibaba.fastjson.JSONObject;importjavax.crypto.Cipher;importjavax.crypto.spec.IvParameterSpec;importjavax.crypto.spec.SecretKeySpec;importjava.io.UnsupportedEncod......
  • 携程 3DES加密解密 java python
    javapackagecom.example;importorg.springblade.core.tool.utils.*;importjavax.annotation.Nullable;importjavax.crypto.Cipher;importjavax.crypto.SecretKeyFactory;importjavax.crypto.spec.DESKeySpec;importjava.util.Objects;publicclassDES3{......
  • js解密日记3 jsentrypt带给我的困扰
    随着技术的不断进步,保护敏感数据已成为开发者的首要任务之一。加密是一种保护数据的方法,JSenCrypt是一款流行的加密库,提供了HTML、Python和Node.js版本。本文将探讨每个版本的特点、优点、缺点,并提供代码示例来演示它们的用法。jsentryptHTML版本优点:客户端加密:jsentrypt......
  • Oracle定义DES加密解密及MD5加密函数示例
    (1)DES加密函数createorreplacefunctionencrypt_des(p_textvarchar2,p_keyvarchar2)returnvarchar2isv_textvarchar2(4000);v_encvarchar2(4000);raw_inputRAW(128);key_inputRAW(128);decrypted_rawRAW(2048);beginv_text:=rpad(p_text,(trunc(len......
  • 给文件加密解密的过程
    加密:tar-czvf-mcw.txt|openssldes3-salt-k'<a?VU<a{sfm*sf1'-outxiaoma.des3解密:openssldes3-d-k'<a?VU<a{sfm*sf1'-salt-inxiaoma.des3|tarxzvf-  ➜machangweimkdirmcwtest➜machangweicdmcwtest➜mcw......
  • 解密Spring Boot:JPA vs. MyBatis,哪个更适合你的项目?
    Hello大家好,我是小米!今天我要和大家聊聊一个在Java开发中经常会遇到的问题,那就是如何在SpringBoot项目中区分何时该使用JPA,何时该使用MyBatis。这个问题一直困扰着很多开发者,但其实只要理清一些基本概念和场景,就能轻松解决。废话不多说,让我们一起深入探讨吧!了解JPA和MyBatis首先,让......