java.security.NoSuchAlgorithmException:MD5withRSA KeyFactory不可用
我尝试使用所有3种可能的方法实例化KeyFactory:
选项1.公共静态KeyFactory getInstance(String algorithm)
选项2。公共静态KeyFactory getInstance(String algorithm,String provider)
但是无论它引发什么异常:
对于选项1: java.security.NoSuchAlgorithmException:MD5withRSA KeyFactory不可用
对于选项3: java.security.NoSuchAlgorithmException:否这样的算法:提供程序xxxxxxxxxx的MD5withRSA
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.PublicKey;
import java.security.Security;
import java.security.Signature;
import java.security.SignatureException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.TreeSet;
import javax.crypto.Cipher;
import org.apache.commons.codec.binary.Base64;
public class KeyTest {
public static void main(String[] args) {
for (Provider provider : Security.getProviders()) {
System.out.println(provider.getInfo());
try {
// Option 3
KeyFactory keyFactory = KeyFactory.getInstance("MD5withRSA", provider);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
// Option 1
try {
KeyFactory keyFactory = KeyFactory.getInstance("MD5withRSA");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
期望此代码为MD5withRSA算法创建KeyFactory的实例,因为我看到它存在于可用提供程序(IBMJCE)之一中。
这是上述程序sysout的一部分,它确认算法MD5withRSA可用:
IBMJCE Provider实现以下内容:
HMAC-SHA1,MD2,MD5,MARS,SHA,MD2withRSA,MD5withRSA,SHA1withRSA,RSA,SHA1withDSA,RC2,RC4,Seal)实现以下目的:
签名算法:SHA1withDSA,SHA1withRSA,MD5withRSA,MD2withRSA,SHA256withRSA,SHA384withRSA,SHA512withRSA