How do I get Java to use my Security provider?

后端 未结 2 676
梦毁少年i
梦毁少年i 2020-12-15 06:35

I wrote a custom security provider for AES/CBC/PKCS5Padding. That works fine.

What settings do I need to add to the Provider in order for Java to recogn

相关标签:
2条回答
  • 2020-12-15 07:26

    Writing the code is the very simplest part of the process. You have already declared that your classes provide a Cipher implementation for AES. This line:

    put("Cipher.AES", "foo.bar.AESCipher");
    

    is pretty much all you need to accomplish the task. Also note that your implementation will automatically be called for all combinations of mode and padding, since you have registered your cipher implementation at the algorithm level.

    Having said that, writing the code was the easy part. You are creating a cipher, so you will need to sign your JAR before it can be installed and configured as a provider. Because the process is somewhat involved I will not copy it all here, rather I will refer you to the Oracle Guide on How to implement a Provider. It's an excellent source for this task.

    If you follow the guide and still have issues, you may need to download and install the JCE Unlimited Strength Policy appropriate to your installed JDK.

    0 讨论(0)
  • 2020-12-15 07:27

    The Java Crypto documentation describes the mechanisms for registering a Provider class:

    • http://docs.oracle.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html#Provider

    The short version is:

    1. Put the provider JAR on the classpath or in the Java installation's extensions directory.
    2. Register the provider:
      • edit the java.security config file (in the Java installation), or
      • at runtime, call Security.addProvider or Security.insertProviderAt.
    0 讨论(0)
提交回复
热议问题