gpt4 book ai didi

java - "java.security.NoSuchAlgorithmException: SHA3-384 MessageDigest not available"与 Java 9

转载 作者:行者123 更新时间:2023-11-29 04:22:51 25 4
gpt4 key购买 nike

我尝试调用下面提到的 hash(String plainText) 函数 -

import java.security.MessageDigest;
import java.lang.Exception;
import java.util.Base64;

public class MyHash {

private MessageDigest messageDigest = null;
private String algo = "SHA3-384";

public String hash(String plainText)
{
byte[] hashBytes = null;

try
{
messageDigest = MessageDigest.getInstance(algo);
messageDigest.update( plainText.getBytes() );
hashBytes = messageDigest.digest();
}
catch(Exception e)
{
e.printStackTrace();
}
return Base64.getEncoder().encodeToString(hashBytes);
}
}

得到了这个错误-

java.security.NoSuchAlgorithmException: SHA3-384 MessageDigest not available
at sun.security.jca.GetInstance.getInstance(java.base@9-internal/GetInstance.java:159)
at java.security.Security.getImpl(java.base@9-internal/Security.java:695)
at java.security.MessageDigest.getInstance(java.base@9-internal/MessageDigest.java:174)
at MyHash.hash(MyHash.java:16)
at Main.main(Main.java:36)

此外,java -version 的输出 -

openjdk version "9-internal"
OpenJDK Runtime Environment (build 9-internal+0-2016-04-14-195246.buildd.src)
OpenJDK 64-Bit Server VM (build 9-internal+0-2016-04-14-195246.buildd.src, mixed mode)

不知道为什么会出现这个错误。任何帮助将不胜感激。

编辑 1:

这些是支持的算法-

    Provider: SUN
Algorithm: SHA1PRNG
Algorithm: NativePRNG
Algorithm: NativePRNGBlocking
Algorithm: NativePRNGNonBlocking
Algorithm: SHA1withDSA
Algorithm: NONEwithDSA
Algorithm: SHA224withDSA
Algorithm: SHA256withDSA
Algorithm: SHA1withDSAinP1363Format
Algorithm: NONEwithDSAinP1363Format
Algorithm: SHA224withDSAinP1363Format
Algorithm: SHA256withDSAinP1363Format
Algorithm: DSA
Algorithm: MD2
Algorithm: MD5
Algorithm: SHA
Algorithm: SHA-224
Algorithm: SHA-256
Algorithm: SHA-384
Algorithm: SHA-512
Algorithm: DSA
Algorithm: DSA
Algorithm: DSA
Algorithm: X.509
Algorithm: PKCS12
Algorithm: JKS
Algorithm: CaseExactJKS
Algorithm: DKS
Algorithm: JavaPolicy
Algorithm: JavaLoginConfig
Algorithm: PKIX
Algorithm: PKIX
Algorithm: Collection
Algorithm: com.sun.security.IndexedCollection
Provider: SunRsaSign
Algorithm: RSA
Algorithm: RSA
Algorithm: MD2withRSA
Algorithm: MD5withRSA
Algorithm: SHA1withRSA
Algorithm: SHA224withRSA
Algorithm: SHA256withRSA
Algorithm: SHA384withRSA
Algorithm: SHA512withRSA
Provider: SunJSSE
Algorithm: RSA
Algorithm: RSA
Algorithm: MD2withRSA
Algorithm: MD5withRSA
Algorithm: SHA1withRSA
Algorithm: MD5andSHA1withRSA
Algorithm: SunX509
Algorithm: NewSunX509
Algorithm: SunX509
Algorithm: PKIX
Algorithm: TLSv1
Algorithm: TLSv1.1
Algorithm: TLSv1.2
Algorithm: TLS
Algorithm: DTLSv1.0
Algorithm: DTLSv1.2
Algorithm: DTLS
Algorithm: Default
Algorithm: PKCS12
Provider: SunJCE
Algorithm: RSA
Algorithm: DES
Algorithm: DESede
Algorithm: DESedeWrap
Algorithm: PBEWithMD5AndDES
Algorithm: PBEWithMD5AndTripleDES
Algorithm: PBEWithSHA1AndDESede
Algorithm: PBEWithSHA1AndRC2_40
Algorithm: PBEWithSHA1AndRC2_128
Algorithm: PBEWithSHA1AndRC4_40
Algorithm: PBEWithSHA1AndRC4_128
Algorithm: PBEWithHmacSHA1AndAES_128
Algorithm: PBEWithHmacSHA224AndAES_128
Algorithm: PBEWithHmacSHA256AndAES_128
Algorithm: PBEWithHmacSHA384AndAES_128
Algorithm: PBEWithHmacSHA512AndAES_128
Algorithm: PBEWithHmacSHA1AndAES_256
Algorithm: PBEWithHmacSHA224AndAES_256
Algorithm: PBEWithHmacSHA256AndAES_256
Algorithm: PBEWithHmacSHA384AndAES_256
Algorithm: PBEWithHmacSHA512AndAES_256
Algorithm: Blowfish
Algorithm: AES
Algorithm: AES_128/ECB/NoPadding
Algorithm: AES_128/CBC/NoPadding
Algorithm: AES_128/OFB/NoPadding
Algorithm: AES_128/CFB/NoPadding
Algorithm: AES_128/GCM/NoPadding
Algorithm: AES_192/ECB/NoPadding
Algorithm: AES_192/CBC/NoPadding
Algorithm: AES_192/OFB/NoPadding
Algorithm: AES_192/CFB/NoPadding
Algorithm: AES_192/GCM/NoPadding
Algorithm: AES_256/ECB/NoPadding
Algorithm: AES_256/CBC/NoPadding
Algorithm: AES_256/OFB/NoPadding
Algorithm: AES_256/CFB/NoPadding
Algorithm: AES_256/GCM/NoPadding
Algorithm: AESWrap
Algorithm: AESWrap_128
Algorithm: AESWrap_192
Algorithm: AESWrap_256
Algorithm: RC2
Algorithm: ARCFOUR
Algorithm: DES
Algorithm: DESede
Algorithm: Blowfish
Algorithm: AES
Algorithm: RC2
Algorithm: ARCFOUR
Algorithm: HmacMD5
Algorithm: HmacSHA1
Algorithm: HmacSHA224
Algorithm: HmacSHA256
Algorithm: HmacSHA384
Algorithm: HmacSHA512
Algorithm: DiffieHellman
Algorithm: DiffieHellman
Algorithm: DiffieHellman
Algorithm: DiffieHellman
Algorithm: DES
Algorithm: DESede
Algorithm: PBE
Algorithm: PBEWithMD5AndDES
Algorithm: PBEWithMD5AndTripleDES
Algorithm: PBEWithSHA1AndDESede
Algorithm: PBEWithSHA1AndRC2_40
Algorithm: PBEWithSHA1AndRC2_128
Algorithm: PBEWithSHA1AndRC4_40
Algorithm: PBEWithSHA1AndRC4_128
Algorithm: PBES2
Algorithm: PBEWithHmacSHA1AndAES_128
Algorithm: PBEWithHmacSHA224AndAES_128
Algorithm: PBEWithHmacSHA256AndAES_128
Algorithm: PBEWithHmacSHA384AndAES_128
Algorithm: PBEWithHmacSHA512AndAES_128
Algorithm: PBEWithHmacSHA1AndAES_256
Algorithm: PBEWithHmacSHA224AndAES_256
Algorithm: PBEWithHmacSHA256AndAES_256
Algorithm: PBEWithHmacSHA384AndAES_256
Algorithm: PBEWithHmacSHA512AndAES_256
Algorithm: Blowfish
Algorithm: AES
Algorithm: GCM
Algorithm: RC2
Algorithm: OAEP
Algorithm: DiffieHellman
Algorithm: DES
Algorithm: DESede
Algorithm: PBEWithMD5AndDES
Algorithm: PBEWithMD5AndTripleDES
Algorithm: PBEWithSHA1AndDESede
Algorithm: PBEWithSHA1AndRC2_40
Algorithm: PBEWithSHA1AndRC2_128
Algorithm: PBEWithSHA1AndRC4_40
Algorithm: PBEWithSHA1AndRC4_128
Algorithm: PBEWithHmacSHA1AndAES_128
Algorithm: PBEWithHmacSHA224AndAES_128
Algorithm: PBEWithHmacSHA256AndAES_128
Algorithm: PBEWithHmacSHA384AndAES_128
Algorithm: PBEWithHmacSHA512AndAES_128
Algorithm: PBEWithHmacSHA1AndAES_256
Algorithm: PBEWithHmacSHA224AndAES_256
Algorithm: PBEWithHmacSHA256AndAES_256
Algorithm: PBEWithHmacSHA384AndAES_256
Algorithm: PBEWithHmacSHA512AndAES_256
Algorithm: PBKDF2WithHmacSHA1
Algorithm: PBKDF2WithHmacSHA224
Algorithm: PBKDF2WithHmacSHA256
Algorithm: PBKDF2WithHmacSHA384
Algorithm: PBKDF2WithHmacSHA512
Algorithm: HmacMD5
Algorithm: HmacSHA1
Algorithm: HmacSHA224
Algorithm: HmacSHA256
Algorithm: HmacSHA384
Algorithm: HmacSHA512
Algorithm: HmacPBESHA1
Algorithm: PBEWithHmacSHA1
Algorithm: PBEWithHmacSHA224
Algorithm: PBEWithHmacSHA256
Algorithm: PBEWithHmacSHA384
Algorithm: PBEWithHmacSHA512
Algorithm: SslMacMD5
Algorithm: SslMacSHA1
Algorithm: JCEKS
Algorithm: SunTlsPrf
Algorithm: SunTls12Prf
Algorithm: SunTlsMasterSecret
Algorithm: SunTlsKeyMaterial
Algorithm: SunTlsRsaPremasterSecret

编辑 2:

Oracle 的 JDK 9.0.1 没有错误

最佳答案

OpenJdk 9 也应该按照下面的链接实现这一点。

JEP 287: SHA-3 Hash Algorithms

尝试在您的环境中运行以下代码,看看支持哪些算法。

 public static void main(String[] args) {

for (Provider provider : Security.getProviders()) {
System.out.println("Provider: " + provider.getName());
for (Provider.Service service : provider.getServices()) {
System.out.println(" Algorithm: " + service.getAlgorithm());
}
}


}

不确定,但我认为您提供的链接指向 Oracle 的 JDK,而您使用的是 openjdk。

关于java - "java.security.NoSuchAlgorithmException: SHA3-384 MessageDigest not available"与 Java 9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48040299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com