bouncycastle provider can't find classes needed for algorithm

后端 未结 3 1872
[愿得一人]
[愿得一人] 2020-12-25 12:53

I\'m trying to use bouncycastle to encrypt a file using a public key. I\'ve registered the provider programatically:

Security.addProvider(new BouncyCastlePro         


        
相关标签:
3条回答
  • 2020-12-25 13:17

    You have a BouncyCastle Security provider installation problem, you need to either

    • Add BouncyCastle to the JRE/JDK $JAVA_HOME/jre/lib/security/java.security file as a provider (be sure that you add it to the JRE you use when running, eg. if you have multiple JRE's/JDK's installed)

    eg.

    security.provider.2=org.bouncycastle.jce.provider.BouncyCastleProvider
    

    (and renumber the security providers below it - don't put it as the highest priority provider).

    • or you can add BouncyCastle programmatically, as you were trying to do above, but in this case the security policy $JAVA_HOME/jre/lib/security/java.policy should be "unlimited" (you can probably download an unlimited policy file from the Java homepage).
    0 讨论(0)
  • 2020-12-25 13:18

    You need to add javapns.jar and bcprove-jdk15on-1.47.jar file in your lib folder

    import javapns.Push;
    
    import org.apache.log4j.BasicConfigurator;
    
    public class SendPushNotification {
    
      public static void main(String[] args) {
    
        try {
    
            BasicConfigurator.configure();
            Push.alert("Hello World!", "Cetificate.p12", "password", false,
                    "mydeviceToken");
    
        } catch (Exception e) {
            System.out.println(e);
        }
    
       }
    
    }
    
    0 讨论(0)
  • 2020-12-25 13:22

    In my case it worked fine one time, but then later I got ClassNotFoundException when trying to use BC. I restarted Tomcat and then it worked fine.

    I think if you redeploy the app, like you do often while developing, it stops working. JNI is another thing which suffers from this problem.

    In our case this isn't a problem. We never redeploy on the test and production systems. I prefer shipping the jar with the app instead of having to manually copy it to the container lib directory.

    0 讨论(0)
提交回复
热议问题