感谢@jdv 的回答。我正在添加更多信息以快速入门和示例。
首先,添加 BouncyCastle maven 依赖项,或者在Maven Central上获取它:
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.56</version>
</dependency>
然后我们可以测试它:
import org.bouncycastle.jcajce.provider.digest.SHA3;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;
@Test
public void testSha3() throws Exception {
String input = "Hello world !";
SHA3.DigestSHA3 digestSHA3 = new SHA3.Digest512();
byte[] digest = digestSHA3.digest(input.getBytes());
System.out.println("SHA3-512 = " + Hex.toHexString(digest));
}
你会得到这个结果(512 位或十六进制的 64 字节):
SHA3-512 = e9a4fd120d684537d57f314d51213ce5acef8ff6974e2b7599674ef0f0a3cf111f0d26ed602db946739da448210fb76a7621d7a8f07728372b10a975f36d8e3
您可以将其与此结果进行比较:https ://duckduckgo.com/?q=sha3+%22Hello+world+!%22&ia=answer