7 Replies Latest reply: Aug 9, 2011 6:47 AM by sabre150 RSS

    Problem with Provider

    881186
      Hi iam a newbee to this Forum and have some problems with the JCA API.
      I try to do somting linke this :

      Signature sign = Signature.getInstance("SHA256WithRSA", "SUN");

      the Compiler notfie some problem

      Exception in thread "main" java.security.NoSuchAlgorithmException: no such algorithm: SHA256WithRSA for provider SUN
           at sun.security.jca.GetInstance.getService(Unknown Source)
           at sun.security.jca.GetInstance.getInstance(Unknown Source)
           at java.security.Signature.getInstance(Unknown Source)
           at pkcs_signer.coconet_package.TestClass.main(TestClass.java:76)

      How i can solve this problem ? i use the SUN Provider.
      I read in the internet i need to Download the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files 6, is this right ? and how i install this ?

      thank you

      Richard from Germany ( Java newbie )
        • 1. Re: Problem with Provider
          EJP
          You may need those files but you also rarely need to specify the provider: Java will find one for you. Try it just specifying the algorithm.
          • 2. Re: Problem with Provider
            881186
            How i can specify the provider ? i want to use the sund provider for example like this :

            Sun sun = new Sun();
                      
            Security.addProvider(sun);
                      
            Signature sign = Signature.getInstance("SHA256withDSA", sun);

            but i have the same Exception no such algorithm: SHA256withDSA for provider SUN

            can me help to solve this problem?
            • 3. Re: Problem with Provider
              EJP
              As I already said, you probably don't need to specify the provider at all. What happened when you tried my suggestion?
              • 4. Re: Problem with Provider
                881186
                Ok i unterstand somting like this :



                Signature sign = Signature.getInstance("SHA256withRSA");
                          
                System.out.println(sign.getAlgorithm());

                the Compiler searches vor a Provider is this right ? and then the compiler find the SUN Provider.

                thanks : )
                • 5. Re: Problem with Provider
                  gimbal2
                  878183 wrote:
                  Ok i unterstand somting like this :



                  Signature sign = Signature.getInstance("SHA256withRSA");
                            
                  System.out.println(sign.getAlgorithm());

                  the Compiler searches vor a Provider is this right ? and then the compiler find the SUN Provider.
                  The compiler only compiles. It is the Java runtime that does it.
                  • 6. Re: Problem with Provider
                    sabre150
                    878183 wrote:
                    Signature sign = Signature.getInstance("SHA256withRSA");
                              
                    System.out.println(sign.getAlgorithm());

                    the Compiler searches vor a Provider is this right ? and then the compiler find the SUN Provider.
                    Since the SUN provider does not provide an implementation for "SHA256withRSA" then no - the JRE (not compiler) does not find the SUN provider. BUT - the JRE does find the "SunRsaSign" provider which does support "SHA256withRSA". You can of course explicitly request the "SunRsaSign" provider using
                          Signature sign = Signature.getInstance("SHA256withRSA","SunRsaSign");
                    • 7. Re: Problem with Provider
                      EJP
                      Or you can leave it to Java to find a provider for whatever you're looking for. No reason to specify it explicitly at all as far as I can see.

                      The only valid case I can think of is if you know you have multiple providers for the algorithm and you have a preference for one of them, for some reason I can't think of.