jmeter的beanshell无法导入jar包

木縰 2023-05-22 17:22:01

beanshell中使用第三方jar包(web3j)无法使用,报错如下

 

2023-05-22 17:12:00,327 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval	Sourced file: inline evaluation of: `` import org.web3j.crypto.Credentials; import org.web3j.crypto.Hash; import org.w . . . '' : Typed variable declaration
2023-05-22 17:12:00,328 WARN o.a.j.m.BeanShellPreProcessor: Problem in BeanShell script. org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval	Sourced file: inline evaluation of: `` import org.web3j.crypto.Credentials; import org.web3j.crypto.Hash; import org.w . . . '' : Typed variable declaration
2023-05-22 17:12:00,369 INFO o.a.j.u.BeanShellTestElement: 签名数据Welcome to Decert!\n\nThis request will not trigger a blockchain transaction or cost any gas fees.\n\nYour authentication status will reset after 24 hours.\n\nWallet address:\n0xEDC7A0D20A563f9948D2D1332937b5f04F9670A2\n\nNonce:\neda03cda-82b3-4666-8834-89137ee0189c

我将jar包放在相关文件夹中,配置了配置文件,也试过放在lib/ext中,以下是相关代码

import org.bouncycastle.util.encoders.Hex;
import org.web3j.crypto.Credentials;
import org.web3j.crypto.Hash;
import org.web3j.crypto.Keys;
import org.web3j.crypto.Sign;


import org.bouncycastle.util.encoders.Hex;



// 钱包私钥
String priKey = "xxxxx";
// 钱包地址
String walletAddress = "0xxxxxxxxxxxx";

// 原文
String content = vars.get("message");

// 原文摘要字节数组
byte[] contentHashBytes = Hash.sha3(content.getBytes());

// 原文摘要16进制字符串
String contentHashHex = Hex.toHexString(contentHashBytes);

Credentials credentials = Credentials.create(priKey);
Sign.SignatureData signMessage = Sign.signPrefixedMessage(contentHashBytes, credentials.getEcKeyPair());
System.out.println(Hex.toHexString(signMessage.getR()));
System.out.println(Hex.toHexString(signMessage.getS()));
System.out.println(Hex.toHexString(signMessage.getV()));

// 签名后的字符串
String signStr = "0x" + Hex.toHexString(signMessage.getR()) + Hex.toHexString(signMessage.getS()) + Hex.toHexString(signMessage.getV());
System.out.println("signStr=" + signStr);
log.info(signStr);

钱包地址,私钥均隐藏可以根据自己实际填写,以上代码是web3进行签名的操作。

 

希望有大佬能够给一些解决方案,不胜感激

 

 

...全文
755 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

5,628

社区成员

发帖
与我相关
我的任务
社区描述
源于测试的引力。集各方资料。欢迎各位入社!同时欢迎各位加好友进群一起交流:qing_an_an
社区管理员
  • 清安无别事
  • 虫无涯
  • 小博测试成长之路
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 欢迎分享各种测试资料
  2. 欢迎共享各种测试资源
  3. 欢迎各界大佬前来入寨

试试用AI创作助手写篇文章吧