Weblogic - java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.JCEMac$DES9797Alg3 [英] Weblogic - java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.JCEMac$DES9797Alg3

查看:85
本文介绍了Weblogic - java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.JCEMac$DES9797Alg3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Java Web 应用程序,我需要使用 3DES 算法生成 MAC.代码在 Weblogic 10.3 上运行没有问题,但是当我尝试在不同的 Weblogic 类似版本 (10.3.1) 中运行应用程序时出现问题.

I am working with a Java Web application and I need to generate a MAC using 3DES algorithm. Code is working without problems on a Weblogic 10.3 but the problem came when I tried to run the application in a different Weblogic, similar version (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' 有可能在另一个地方寻找吗?我已请求服务器管理员将库复制到已背书目录中,但我不确定这是否会起作用以及发生这种情况的方式.

I do no understand why error says that org.bouncycastle.jce.provider.JCEMac$DES9797Alg3 is not there. It is possible that 'java.security' is looking in another place? I have requested to the server administrator to copy the library in the endorsed directory, but not I am not sure if this is going to work and way this is happening.

请注意,即使我删除了 'Security.addProvider(new BouncyCastleProvider());'行,在可用提供商列表中,列出了 BC.

Notice that even if I remove 'Security.addProvider(new BouncyCastleProvider());' line, in the list of available providers, BC is listed.

这是我得到的提供者列表:

This is the list of providers I got:

-- -- --
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 在那里,而且,和我在我的战争文件中得到的版本相同.

BC is there, moreover, the same version I got inside my war file.

我在谷歌上搜索了很多小时都没有运气,希望有人能指出我正确的方向.

I have googled many hours with no luck, hope someone can point me to the right direction.

推荐答案

在 google 上花费数小时试图修复更改代码的错误后,在服务器域 lib 目录中添加库解决了问题.反正我还是不明白为什么会这样.

After spending many hours on google trying to fix the error doing change in the code, the problem was solved adding the library in the server domain lib directory. Anyway, I still do not understand why this happens.

这篇关于Weblogic - java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.JCEMac$DES9797Alg3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆