Weblogic的 - 抛出java.lang.ClassNotFoundException:org

2019-09-17 15:39发布

我有一个Java Web应用程序的工作,我需要生成一个MAC使用3DES算法。 代码工作没有问题在Weblogic 10.3,但是当我试图运行在不同的WebLogic应用程序的问题就来了,类似的版本(10.3.1)。

这是我的代码:

public String getMac(String inkey, String data) throws Exception {

    byte[] out = new byte[8];

    try {

        // if I commend this line, the result is the same
        Security.addProvider(new BouncyCastleProvider());

        // this loop proves the BC provider is there
        for (Provider p : Security.getProviders()) {

            log.debug("--");
            log.debug(p.getName());
            log.debug(p.getInfo());
        }

        try {

            BouncyCastleProvider bc = new BouncyCastleProvider();

            // class is there, no problem
            log.debug("info" + bc.getInfo());

            DES9797Alg3 alg3 = new DES9797Alg3();

            // class is there, no problem
            log.debug("alg3" + alg3.toString());

        } catch (Exception e) {
            log.error("error BouncyCastleProvider classes");
        }

        log.debug("length: " + inkey.length());

        if (inkey.length() < 48)
            inkey += inkey.substring(0, 16);

        byte[] rawkey = hexStringToByteArray(inkey);
        DESedeKeySpec keyspec = new DESedeKeySpec(rawkey);
        SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("DESede");
        SecretKey key = keyfactory.generateSecret(keyspec);

        Mac mac = Mac.getInstance("ISO9797Alg3Mac");

        mac.init(key);

        mac.update(data.getBytes());

        mac.doFinal(out, 0);

    } catch (Exception e) {

        log.error("Error generating MAC X9_19", e);

        throw new Exception("Error generating MAC X9_19", e);

    }

这是我的错误:

Caused by: java.security.InvalidKeyException: No installed provider supports this key: com.sun.crypto.provider.DESedeKey
    at javax.crypto.Mac.a(DashoA13*..)
    at javax.crypto.Mac.init(DashoA13*..)
    at es.indra.netplus.sec.services.util.UtilMac.getMac(UtilMac.java:180)
    ... 73 more
Caused by: java.security.NoSuchAlgorithmException: class configured for Mac(provider: BC)cannot be found.
    at java.security.Provider$Service.getImplClass(Provider.java:1268)
    at java.security.Provider$Service.newInstance(Provider.java:1220)
    ... 76 more
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.JCEMac$DES9797Alg3
    at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:283)
    at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:256)
    at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:54)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:176)
    at weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:35)
    at java.security.Provider$Service.getImplClass(Provider.java:1262)

我不明白,为什么错误说org.bouncycastle.jce.provider.JCEMac$DES9797Alg3是不存在的。 这可能是“java.security”期待在另一个地方? 我已经要求服务器管理员到库中赞同目录复制,但不是我不知道,如果这是去工作和生活方式发生这种情况。

请注意,即使我删除“Security.addProvider(新BouncyCastleProvider());” 线,在现有供应商的名单,BC上市。

这是供应商我得到的名单:

-- -- --
CSSX509CertificateFactoryProvider
CSS JDK CertPath provider
1.0
-- -- --
SUN
SUN (DSA key/parameter generation; DSA signing; SHA-1, MD5 digests; SecureRandom; X.509 certificates; JKS keystore; PKIX CertPathValidator; PKIX CertPathBuilder; LDAP, Collection CertStores, JavaPolicy Policy; JavaLoginConfig Configuration)
1.6
-- -- --
SunRsaSign
Sun RSA signature provider
1.5
-- -- --
SunJSSE
Sun JSSE provider(PKCS12, SunX509 key/trust factories, SSLv3, TLSv1)
1.6
-- -- --
SunJCE
SunJCE Provider (implements RSA, DES, Triple DES, AES, Blowfish, ARCFOUR, RC2, PBE, Diffie-Hellman, HMAC)
1.6
-- -- --
SunJGSS
Sun (Kerberos v5, SPNEGO)
1.0
-- -- --
SunSASL
Sun SASL provider(implements client mechanisms for: DIGEST-MD5, GSSAPI, EXTERNAL, PLAIN, CRAM-MD5; server mechanisms for: DIGEST-MD5, GSSAPI, CRAM-MD5)
1.5
-- -- --
XMLDSig
XMLDSig (DOM XMLSignatureFactory; DOM KeyInfoFactory)
1.0
-- -- --
SunPCSC
Sun PC/SC provider
1.6
-- -- --
WebLogicCertPathProvider
WebLogic CertPath Provider JDK CertPath provider
1.0
-- -- --
WLSJDKCertPathProvider
WebLogic JDK CertPath provider
1.0
-- -- --
BC
BouncyCastle Security Provider v1.46
1.46

BC是存在的,而且,同一版本里面我我的战争文件了。

我用Google搜索多小时,没有运气,希望有人能为我指向正确的方向。

Answer 1:

在谷歌花费很多时间试图修复错误做的代码更改后,问题解决了在服务器领域lib目录中添加库。 不管怎样,我还是不明白为什么会这样。



文章来源: Weblogic - java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.JCEMac$DES9797Alg3