sm2私钥加签,公钥来验签的算法怎么写的?

我用的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));
    }

结果不对。

阅读 963
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进