java.security.NoSuchAlgorithmException: Cannot find any provider supporting RSA

 

最近在导入一个项目时,跑起来遇到了一个问题。 创建数据库连接时,未识别的 RSA 

Servlet.service() for servlet [] in context with path [/] threw exception [Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.lang.IllegalArgumentException: Failed to decrypt.] with root cause

java.security.NoSuchAlgorithmException: Cannot find any provider supporting RSA

 

 解决办法:

   修改 java.security 文件

   我本机的路径是 C:\Disk-D\Program Files\Java\jdk1.8.0_201\jre\lib\security\java.security

security.provider.1=sun.security.provider.Sun
security.provider.2=sun.security.rsa.SunRsaSign
security.provider.3=sun.security.ec.SunEC
security.provider.4=com.sun.net.ssl.internal.ssl.Provider
security.provider.5=com.sun.crypto.provider.SunJCE
security.provider.6=sun.security.jgss.SunProvider
security.provider.7=com.sun.security.sasl.Provider
security.provider.8=org.jcp.xml.dsig.internal.dom.XMLDSigRI
security.provider.9=sun.security.smartcardio.SunPCSC
security.provider.10=sun.security.mscapi.SunMSCAPI
security.provider.11=org.bouncycastle.jce.provider.BouncyCastleProvider

1~10是系统默认的,11是自己添加的。 同时在  C:\Disk-D\Program Files\Java\jdk1.8.0_201\jre\lib\ext 目录下 添加 bcprov-jdk15on-1.58.jar 包。  jar包的下载地址:https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on/1.58

即解决了问题。

 

PS:

 security.provider.2=sun.security.rsa.SunRsaSign 这行显然已经导入了RSA,不知道为啥还提示没有 RSA provider ???  

 用反编译工具查看

public final class BouncyCastleProvider extends Provider
  implements ConfigurableProvider
{
  private static String info = "BouncyCastle Security Provider v1.58";
  public static final String PROVIDER_NAME = "BC";
  public static final ProviderConfiguration CONFIGURATION = new BouncyCastleProviderConfiguration();
  private static final Map keyInfoConverters = new HashMap();
  private static final String SYMMETRIC_PACKAGE = "org.bouncycastle.jcajce.provider.symmetric.";
  private static final String[] SYMMETRIC_GENERIC = { "PBEPBKDF1", "PBEPBKDF2", "PBEPKCS12", "TLSKDF" };
  private static final String[] SYMMETRIC_MACS = { "SipHash", "Poly1305" };
  private static final String[] SYMMETRIC_CIPHERS = { "AES", "ARC4", "ARIA", "Blowfish", "Camellia", "CAST5", "CAST6", "ChaCha", "DES", "DESede", "GOST28147", "Grainv1", "Grain128", "HC128", "HC256", "IDEA", "Noekeon", "RC2", "RC5", "RC6", "Rijndael", "Salsa20", "SEED", "Serpent", "Shacal2", "Skipjack", "SM4", "TEA", "Twofish", "Threefish", "VMPC", "VMPCKSA3", "XTEA", "XSalsa20", "OpenSSLPBKDF", "DSTU7624" };
  private static final String ASYMMETRIC_PACKAGE = "org.bouncycastle.jcajce.provider.asymmetric.";
  private static final String[] ASYMMETRIC_GENERIC = { "X509", "IES" };
  private static final String[] ASYMMETRIC_CIPHERS = { "DSA", "DH", "EC", "RSA", "GOST", "ECGOST", "ElGamal", "DSTU4145", "GM" };
  private static final String DIGEST_PACKAGE = "org.bouncycastle.jcajce.provider.digest.";
  private static final String[] DIGESTS = { "GOST3411", "Keccak", "MD2", "MD4", "MD5", "SHA1", "RIPEMD128", "RIPEMD160", "RIPEMD256", "RIPEMD320", "SHA224", "SHA256", "SHA384", "SHA512", "SHA3", "Skein", "SM3", "Tiger", "Whirlpool", "Blake2b", "DSTU7564" };
  private static final String KEYSTORE_PACKAGE = "org.bouncycastle.jcajce.provider.keystore.";
  private static final String[] KEYSTORES = { "BC", "BCFKS", "PKCS12" };
  private static final String SECURE_RANDOM_PACKAGE = "org.bouncycastle.jcajce.provider.drbg.";
  private static final String[] SECURE_RANDOMS = { "DRBG" };

  public BouncyCastleProvider()
  {
    super("BC", 1.58D, info);
    AccessController.doPrivileged(new PrivilegedAction()
    {
      public Object run()
      {
        BouncyCastleProvider.this.setup();
        return null;
      }
    });
  }

在 ASYMMETRIC_CIPHERS 定义了一个 “RSA”。  具体情况未深究。

 

posted @ 2019-05-30 16:50  Greys  阅读(6051)  评论(0编辑  收藏  举报