MessageDigest.getInstance (algorithm) always throws NoSuchAlgorithmException

I am creating a simple password repository / generator, and now I am working on a part of my code repository and writing code to encrypt passwords. I am using MessageDigest.

However, when I try to select an algorithm, it always throws a NoSuchAlgorithmException. I am trying to use SHA-1 or SHA-256. I searched everywhere and I cannot find a solution. EDIT: I forgot to mention that I tried "SHA-1", "SHA-256" and "MD5". Nothing works.

My method:

private static String generateHash(String input) throws NoSuchAlgorithmException {
    MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
    messageDigest.update(input.getBytes());
    String encryptedString = new String(messageDigest.digest());
    System.out.println("encryptedString :: " + encryptedString);
    return encryptedString;
}

(I only print out encryptedString for debugging purposes)

I am using JDK 1.8.0_91 and IntelliJ IDEA 1.5.0.2.

EDIT: , , . throws NoSuchAlgorithmException try/catch, NoSuchAlgorithmException. , , .

+4
2

Oracle MessageDigest:

Java MessageDigest:

MD5, SHA-1, SHA-256

Oracle JVM MD2, MD5, SHA-1, SHA-256, SHA-384 SHA-512

0

SHA-128, , . Message Digest .

NB, " ".

0

All Articles