如何让Java使用我的安全提供程序? [英] How do I get Java to use my Security provider?

查看:64
本文介绍了如何让Java使用我的安全提供程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为AES / CBC / PKCS5Padding编写了一个自定义安全提供程序。这很好。

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

我需要将哪些设置添加到 Provider ,以便Java将其识别为上述算法的有效提供者?我已经

What settings do I need to add to the Provider in order for Java to recognize it as a valid provider for the above algorithm? I already have

public class FooBarProvider extends Provider {
  public FooBarProvider() {
    super("FooBar", 1.0, "Provider for AES.");
    put("Cipher.AES", "foo.bar.AESCipher");
  }
}

其中后一个参数是实际的 CipherSpi 完成工作。我在哪里注册它支持CBC和PKCS5Padding的事实?目前要求相关的 Cipher 不会返回我的班级实例:

where the latter argument is the actual CipherSpi that does the work. Where do I register the fact that it supports CBC and PKCS5Padding? Currently asking for a relevant Cipher does not return an instance of my class:

Security.insertProviderAt(new FooBarProvider(), 1);
Cipher cip = Cipher.getInstance("AES/CBC/PKCS5Padding");
System.out.println(cip.getProvider()); //prints "SunJCE version 1.7"


推荐答案

编写代码是这个过程中最简单的部分。您已经声明您的类为AES提供了Cipher实现。这一行:

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");

几乎是完成任务所需的全部内容。另请注意,由于您已在算法级别注册了密码实现,因此将自动为模式 padding 的所有组合调用您的实现。

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.

话虽如此,编写代码很容易。您正在创建密码,因此在安装和配置JAR之前,您需要对其进行签名。因为这个过程有点牵扯,我不会在这里全部复制,而是我会引用你的 Oracle如何实施提供商指南。这是完成此任务的绝佳来源。

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.

如果您按照指南操作仍有问题,则可能需要下载并安装 JCE Unlimited Strength Policy 适合您安装的JDK。

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.

这篇关于如何让Java使用我的安全提供程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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