• 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-DProgram FilesJavajdk1.8.0_201jrelibsecurityjava.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-DProgram FilesJavajdk1.8.0_201jrelibext 目录下 添加 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”。  具体情况未深究。

  • 相关阅读:
    H5新增属性02
    h5新增属性
    javascript基础
    多列布局和弹性盒模型详解
    边框图片+盒子倒影
    CSS新增边框属性
    css3选择器
    css3基础
    h5新增-2
    h5新增
  • 原文地址:https://www.cnblogs.com/greys/p/10950525.html
Copyright © 2020-2023  润新知