I tried to invoke hash(String plainText)
function mentioned below -
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);
}
}
and got this error -
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)
Also, the output of 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)
Don't know why I am getting this error. Any help will be appreciated.
Edit 1 :
These are the algorithms supported -
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
Edit 2 :
No errors with Oracle's JDK 9.0.1
I have updated my JDK to Oracle's JDK 9.0.1 and can able to use SHA3-384
without any errors.
Output of java -version
after updating -
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)