5,628
社区成员




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进行签名的操作。
希望有大佬能够给一些解决方案,不胜感激