我用的hutool工具
它的代码
公钥不是比私钥要短一些吗?
我封装了下
public static String getSm2SignByPrivateKey(String privateKey, String text) {
SM2 sm2 = new SM2(privateKey, null, null);
sm2.usePlainEncoding();
byte[] sign = sm2.sign(text.getBytes(), null);
return HexUtil.encodeHexStr(sign);
}
public static boolean verifySm2SignByPublicKey(String publicKey, String text, String sign) {
SM2 sm2 = new SM2(null, ECKeyUtil.toSm2PublicParams(publicKey));
sm2.usePlainEncoding();
return sm2.verify(text.getBytes(), HexUtil.decodeHex(sign));
}
结果不对。