【群答疑】jmeter实现aes解密
需求
调用aesDecrypt方法解密
String keyword = "eb9dc4aa69d6582693ba2e3ebe2fe260";
String data = "C4564EEBA5C956464B1A050F4961A7C5A41D33414BA8175B668ACF8BFAB228D484BD2FB175C854F5DDBF13470D61AD073E6432C45B81303578BF004917B8DEE4";
期望结果:
{"transType": "V2101","transDate": "2010-12-24 12:25:15"}
方案:beanshell引入java文件
SHATest.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | package com.test; import java.security.SecureRandom; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; public class SHATest { private static int digit = 128; private static String keyword = "eb9dc4aa69d6582693ba2e3ebe2fe260" ; // aes解密 public static String aesDecrypt(String content, String password) throws Exception { byte [] contentByte = parseHexStr2Byte(content); KeyGenerator kgen = KeyGenerator.getInstance( "AES" ); SecureRandom random = SecureRandom.getInstance( "SHA1PRNG" ); random.setSeed(password.getBytes( "UTF-8" )); kgen.init(digit, random); SecretKey secretKey = kgen.generateKey(); byte [] enCodeFormat = secretKey.getEncoded(); SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES" ); Cipher cipher = Cipher.getInstance( "AES/ECB/PKCS5Padding" ); cipher.init(Cipher.DECRYPT_MODE, key); byte [] result = cipher.doFinal(contentByte); String returStr = new String(result, "UTF-8" ); return returStr; } /** * 将16进制转换为二进制 */ public static byte [] parseHexStr2Byte(String hexStr) { if (hexStr.length() < 1) return null ; byte [] result = new byte [hexStr.length() / 2]; for ( int i = 0; i < hexStr.length() / 2; i++) { int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16); int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16); result[i] = ( byte ) (high * 16 + low); } return result; } } |
beanshell脚本
1 2 3 4 5 6 7 | source( "E:\\myjava\\demo\\src\\main\\java\\com\\test\\SHATest.java" ); String keyword = "eb9dc4aa69d6582693ba2e3ebe2fe260" ; String data = "C4564EEBA5C956464B1A050F4961A7C5A41D33414BA8175B668ACF8BFAB228D484BD2FB175C854F5DDBF13470D61AD073E6432C45B81303578BF004917B8DEE4" ; String res = SHA256.aesDecrypt(data,keyword); log.info( "=========" +res); |
结果:解密成功
__EOF__

本文作者:持之以恒(韧)
关于博主:擅长性能、全链路、自动化、企业级自动化持续集成(DevTestOps)、测开等
面试必备:项目实战(性能、自动化)、简历笔试,https://www.cnblogs.com/uncleyong/p/15777706.html
测试提升:从测试小白到高级测试修炼之路,https://www.cnblogs.com/uncleyong/p/10530261.html
欢迎分享:如果您觉得文章对您有帮助,欢迎转载、分享,也可以点击文章右下角【推荐】一下!
关于博主:擅长性能、全链路、自动化、企业级自动化持续集成(DevTestOps)、测开等
面试必备:项目实战(性能、自动化)、简历笔试,https://www.cnblogs.com/uncleyong/p/15777706.html
测试提升:从测试小白到高级测试修炼之路,https://www.cnblogs.com/uncleyong/p/10530261.html
欢迎分享:如果您觉得文章对您有帮助,欢迎转载、分享,也可以点击文章右下角【推荐】一下!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构