引入以下依赖

<dependency>
    <groupId>org.bouncycastle</groupId>
    <artifactId>bcprov-jdk15to18</artifactId>
    <version>1.68</version>
</dependency>

SM3Test.java

import org.bouncycastle.crypto.digests.SM3Digest;
import org.bouncycastle.util.encoders.Hex;

public class SM3Test {

    public static void main(String[] args) {
        System.out.println(generateSM3HASH("123456"));
    }

    /**
     * SM3 摘要计算
     *
     * @param src
     * @return
     */
    public static String generateSM3HASH(String src) {
        byte[] md = new byte[32];
        byte[] msg1 = src.getBytes();
        SM3Digest sm3 = new SM3Digest();
        sm3.update(msg1, 0, msg1.length);
        sm3.doFinal(md, 0);
        String s = new String(Hex.encode(md));
        return s.toUpperCase();
    }

}

参考链接:https://github.com/hwyqb/SM2_SM3_SM4Encrypt

相关文章:

  • 2021-10-23
  • 2022-12-23
  • 2021-11-16
  • 2021-09-13
  • 2022-12-23
  • 2021-10-28
  • 2022-12-23
  • 2021-06-04
猜你喜欢
  • 2022-12-23
  • 2021-12-12
  • 2021-06-04
  • 2022-12-23
  • 2022-12-23
  • 2021-05-27
  • 2021-08-26
相关资源
相似解决方案