I am doing some cryptography tests, by executing the following line of code:
Signature sgn = Signature.getInstance( "MD5" );
I get the error:
java.security.NoSuchAlgorithmException: MD5 Signature not available
I have tried SHA, SHA256, ... It is always the same, when in other cases it did not fail, for example:
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.Signature;
public class TestAlgoriths {
public static void main( String [] args ) {
try {
MessageDigest msgDg = MessageDigest.getInstance( "MD5" );
} catch (NoSuchAlgorithmException e) {
System.err.println(
"ERR -> Generando MessageDigest... \n" + e.toString( ));
}
try {
Signature dsa = Signature.getInstance( "MD5" );
} catch (NoSuchAlgorithmException e) {
System.err.println(
"ERR -> Generando Signature... \n" + e.toString( ));
}
}
} //class
If I can get the MessageDigest instance using MD5.
Available algorithm signatures:
MD2withRSA
MD5andSHA1withRSA
MD5withRSA
NONEwithDSA
NONEwithECDSA
NONEwithRSA
SHA1withDSA
SHA1withECDSA
SHA1withRSA
SHA224withDSA
SHA224withECDSA
SHA224withRSA
SHA256withDSA
SHA256withECDSA
SHA256withRSA
SHA384withECDSA
SHA384withRSA
SHA512withECDSA
SHA512withRSA
I get them with the following class:
/**
* Gets a list of signature algorithms supported by your Java installation
* From: https://stackoverflow.com/questions/35922727
*
*/
import java.security.Provider;
import java.security.Provider.Service;
import java.security.Security;
import java.util.TreeSet;
public class ShowAlgoriths {
public static void main( String [] args ) {
Provider[] providers = Security.getProviders();
System.out.println("Disponibles " + providers.length + " providers.");
TreeSet<String> algorithms = new TreeSet<>();
for (Provider provider : providers) {
for (Service service : provider.getServices( )) {
if (service.getType().equals("Signature")) {
algorithms.add(service.getAlgorithm( ));
}
}
}
System.out.println("\nAlgoritmos: ");
for (String algorithm : algorithms) {
System.out.println(algorithm);
}
}
} //class
Edited:
I am working on Windows7 with Netbeans 8.2
java version "1.8.0_161"
I take the compiled files to another computer, run in console and same result.
Actually the problem is not getting
MessageDigest
fromMD5
it is trying to get the signature fromMD5
, actually this is wrong:The signature for
MD5
must be obtained in this way:This is a test to generate the signature instance with DSA, SHA1withRSA and MD5withRSA, I can even print its algorithm and provider: