7 Replies Latest reply on Aug 8, 2013 8:46 AM by sfcoy

    java.security.NoSuchAlgorithmException after deploying application on JBoss AS 7

    sunilml21

      Hello,

       

      I am trying to deploy my application on JBoss AS 7. Before I had my application successfully running on JBoss 4

       

      Now I am facing a problem in encryption after deploying my application on JBoss AS 7.

       

      My code uses javax.crypto.SecretKeyFactory which can be found in jce.jar. I have created a new module in JBoss and placed this jar along with other required jars[like sunjce_provider.jar, local_policy.jar]. Also I declared this module as dependencies in MANIFEST.MF of my ear.

       

      ear is deployed without any errors. But when I actually access login page of my application it is throwing the following execption when it actually tries to encrypt the password entered in login page.

           java.security.NoSuchAlgorithmException: PBEwithMD5andDES SecretKeyFactory not available

                at javax.crypto.SecretKeyFactory.<init>(DashoA13*..)   

                at javax.crypto.SecretKeyFactory.getInstance(DashoA13*..)

       

       

      The exact line in my code where this exception was thrown is

       

      SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEwithMD5andDES");

       

      The same application is running well in JBoss 4.

       

      I think I am mising some dependency configuration required to run this code segment. But I am not able to figure it out from last 2 days. I checked few blogs related to similar error. But nothing helped me so far.

       

      Please help me in resolving this error. Let me know if more details are required.

       

       

      Thanks,

      Sunil

        • 1. Re: java.security.NoSuchAlgorithmException after deploying application on JBoss AS 7
          ybxiang.china

          I think you need to configure your security domain in standalon.xml at first.

          You can NOT just throw your applictions into jboss AS 7 deployments directory.

          • 2. Re: java.security.NoSuchAlgorithmException after deploying application on JBoss AS 7
            sfcoy

            I wrote a test bean

            {code:java}@Startup

            @Singleton

            public class NoSuchAlgorithmExceptionTestBean {

             

             

                private final Logger logger = Logger.getLogger(NoSuchAlgorithmExceptionTestBean.class.getName());

               

                @PostConstruct

                void startup() throws NoSuchAlgorithmException {

                    SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEwithMD5andDES");

                    logger.info("Started");

                }

            }{code}

            which deploys and runs on every version of AS 7 between 7.0.2 and 7.2.0 with no additional server configuration or custom modules.

             

            So it looks like you have broken something somewhere. It seems like your custom module is redundant, at least when running Sun/Oracle Java.

            1 of 1 people found this helpful
            • 3. Re: java.security.NoSuchAlgorithmException after deploying application on JBoss AS 7
              sunilml21

              Hi Stephen,

               

                   I created custom module for jre libraries[sunjce_provider.jar, local_policy.jar] since I was getting java.lang.NoClassDefFoundError otherwise. Is there any other way include jre libraries?

              • 4. Re: java.security.NoSuchAlgorithmException after deploying application on JBoss AS 7
                sfcoy

                Exactly which class is not found?

                 

                What Java implementation are you running? Please show the output of "java -version".

                 

                Also, which version of JBossAS/WildFly are you running?

                • 5. Re: java.security.NoSuchAlgorithmException after deploying application on JBoss AS 7
                  sunilml21

                  Sorry. I was wrong. I tried again by removing custom module for jre libraries. I am not getting NoClassDefFoundError. But I am still getting NoSuchAlgorithmException even after removing redundant custom module.

                   

                  Also I tried to create  SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEwithMD5andDES"); in a test project as you did. I got the intance of SecretKeyFactory without any error!

                   

                  Now I am sure that I have messed up some configuration in my actual project. I will try to redeploy by removing unnecessary module configurations and post my results here.

                  • 6. Re: java.security.NoSuchAlgorithmException after deploying application on JBoss AS 7
                    sunilml21

                    Hi,

                     

                    I solved this problem by adding dependency in module.xml of my custom module

                    <dependencies>

                           <module name="javax.api" slot="main" export="true" />

                    </dependencies>

                     

                    The code SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEwithMD5andDES"); was in one of the jar which was in my custom module. So it was not able to find that algorithm which was actually present in jre library. It started working once I added above dependency configuration for my custom module.

                     

                    It was working in test project since jre libraries were available directly to the test war that I deployed.

                     

                    @Stephen Coy

                    I was actually getting NoClassDefFoundError for the classes present in jsse.jar and jce.jar. I included these jars by creating modules. I hope this is the correct way to include them. Please correct me if I am wrong.

                    • 7. Re: java.security.NoSuchAlgorithmException after deploying application on JBoss AS 7
                      sfcoy

                      Sunil M L wrote:

                       

                      ...

                      I was actually getting NoClassDefFoundError for the classes present in jsse.jar and jce.jar. I included these jars by creating modules. I hope this is the correct way to include them. Please correct me if I am wrong.

                      I think you just need to add a dependency on the sun.jdk module.