openjdk 使用

曾经试图在Java和OpenJDK中使用椭圆曲线密码术 (ECC)的每个人要么被迫使用Bouncy Castle,要么被SunEC提供者弄糊涂了 。 SunEC提供程序根据文档 (报价)提供以下算法:

AlgorithmParameters 欧共体
KeyAgreement ECDH
KeyFactory 欧共体
KeyPairGenerator 欧共体
Signature ECDSA没有
SHA1withECDSA
SHA256withECDSA SHA3​​84withECDSA SHA512withECDSA

不幸的是,OpenJDK没有附带该提供程序。 但是,任何真正想尝试Java内置ECC功能的人都可能会尝试将sunec.jar(包含提供程序)简单地添加到jre / lib / ext /文件夹中。 但是,当尝试使用提供程序时,这些家伙一定会惊讶地擦着眼睛。 事情与刚开始时看起来不一样...

假设我们将库添加到正确的文件夹中,我们的OpenJDK注意到了它,并且我们可以成功地编译以下代码而没有任何例外:

package eccprovidertest;import java.security.Provider;
import java.security.Provider.Service;
import java.security.Security;
import sun.security.ec.SunEC;/*** ECC Provider Test.* @author  Christopher Meyer - christopher.meyer@rub.de* @version 0.1* Oct 23, 2013*/
public class ECCProviderTest {/*** @param args the command line arguments*/public static void main(final String[] args) {Provider sunEC = new SunEC();Security.addProvider(sunEC);for(Service service : sunEC.getServices()) {System.out.println(service.getType() + ": " + service.getAlgorithm());}}}

如果最终使用OpenJDK(Java版本“ 1.7.0_25”)运行它,则会得到以下输出:

KeyFactory: EC
AlgorithmParameters: EC

哇! 这不是一个非常有用的提供程序.....承诺的算法在哪里? 让我们尝试使用Oracle JDK来运行代码,只是为了好玩:

KeyFactory: EC
AlgorithmParameters: EC
Signature: NONEwithECDSA
Signature: SHA1withECDSA
Signature: SHA256withECDSA
Signature: SHA384withECDSA
Signature: SHA512withECDSA
KeyPairGenerator: EC
KeyAgreement: ECDH

惊喜,惊喜! 那是您开始揉眼睛的时刻! 这里是算法,但是为什么仅在使用Oracle JDK时才可用?

这样做的原因隐藏在提供程序的代码中。 以下几行摘自sun.security.ec.SunEC :

private static final long serialVersionUID = -2279741672933606418L;// flag indicating whether the full EC implementation is present
// (when native library is absent then fewer EC algorithms are available)
private static boolean useFullImplementation = true;
static {try {AccessController.doPrivileged(new PrivilegedAction() {public Void run() {System.loadLibrary("sunec"); // check for native libraryreturn null;}});} catch (UnsatisfiedLinkError e) {useFullImplementation = false;}
}public SunEC() {super("SunEC", 1.7d, "Sun Elliptic Curve provider (EC, ECDSA, ECDH)");// if there is no security manager installed, put directly into// the provider. Otherwise, create a temporary map and use a// doPrivileged() call at the end to transfer the contentsif (System.getSecurityManager() == null) {SunECEntries.putEntries(this, useFullImplementation);} else {Map<Object, Object> map = new HashMap<Object, Object>();SunECEntries.putEntries(map, useFullImplementation);AccessController.doPrivileged(new PutAllAction(this, map));}
}

此外,在将某些条目添加到列表之后,可以在SunECEntries类中找到以下内容:

/** Register the algorithms below only when the full ECC implementation* is available*/
if (!useFullImplementation) {return;
}

好的,这说明了行为。 仅当可以成功加载本机库(在Windows计算机上为libsunec.so或sunec.dll)时,才存在算法。 在我们的情况下,显然缺少该库(因为我们仅复制了sunec.jar文件)。

不幸的是,如果我们阅读了提供者的文档,我们将会知道:

“ […] Java类打包到JRE扩展目录中已签名的sunec.jar中,而C ++和C函数打包到JRE本机库目录中的libsunec.so或sunec.dll中。 如果不存在本机库,则该提供者已注册为支持较少的ECC算法(省略了KeyPairGenerator,Signature和KeyAgreement)。”

不幸的是,这是我们自己急于采取的行动,这浪费了我们宝贵的开发时间。 摘自:有时候阅读JavaDocs确实很有帮助……。 (但不像调试工作那样富有教育意义)。

参考: Java安全和相关主题博客中的JCG合作伙伴 Christopher Meyer的如何将ECC与OpenJDK结合使用 。

翻译自: https://www.javacodegeeks.com/2013/10/how-to-use-ecc-with-openjdk.html

openjdk 使用

openjdk 使用_如何在OpenJDK中使用ECC相关推荐

  1. figma设计_如何在Figma中构建设计入门套件(第1部分)

    figma设计 Figma教程 (Figma Tutorial) Do you like staring at a blank canvas every time you start a new pr ...

  2. 在excel日期比对大小_如何在Excel中防止分组日期

    在excel日期比对大小 As a teenager, group dates can be fun. If you have strict parents, that might be the on ...

  3. 表格在整个html居中显示,html 表格字符居中显示_如何在HTML中居中显示表格?

    html 表格字符居中显示_如何在HTML中居中显示表格? html 表格字符居中显示_如何在HTML中居中显示表格? html 表格字符居中显示 HTML table provides the ab ...

  4. java 正则表达式 开头_如何在Java中修复表达式的非法开头

    java 正则表达式 开头 您是否遇到过这个令人难以置信的错误,想知道如何解决它? 让我们仔细阅读一下,研究如何解决表达式Java非法开头错误. 这是一个动态错误,这意味着编译器会发现某些不符合Jav ...

  5. python 线性回归模型_如何在Python中建立和训练线性和逻辑回归ML模型

    python 线性回归模型 Linear regression and logistic regression are two of the most popular machine learning ...

  6. 合并的表格怎么加横线_如何在excel中文字后面加横线

    如何在excel中文字后面加横线以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 如何在excel中文字后面加横线 好办啊 ...

  7. excel 重复方差分析_如何在Excel中运行方差方差分析的两种方法

    excel 重复方差分析 Recently, we looked at how to Perform a One-Way Analysis of Variance in Excel. In today ...

  8. 符号在excel中的引用_如何在Excel中添加项目符号

    &符号在excel中的引用 There's no built-in feature for bullets in Excel, like there is in a Word document ...

  9. python多项式回归_如何在Python中实现多项式回归模型

    python多项式回归 Let's start with an example. We want to predict the Price of a home based on the Area an ...

最新文章

  1. 怎样获取网站的域名_搭建一个网站,通常的6大步骤你知道吗?
  2. linux基础学习7
  3. thinkphp3.2.3 调用自定义模型提示找不到类_面试BAT必问的JVM,今天我们来说一说它类加载器的底层原理...
  4. 数据库每日一题 2020.05.21
  5. 基于Keras的卷积神经网络(CNN)可视化
  6. 栈的效率为什么比堆高?为什么栈的运行速度比堆快?
  7. 解决NION‘. Failed rule: ‘orderByClause clusterByClause distributeByClause sortByClause limitClause can
  8. Linux系统编程 -- 多线程之基于阻塞队列生产者与消费者模型
  9. 楼主,不知道为什么这么流行
  10. linux交叉编译环境变量设置,arm-linux-gcc安装 和 环境变量设置
  11. 我的CSDN博客下载器,下载博客文章保存为mht文件
  12. linux如何抓包是什么,linux抓包命令是什么
  13. smart原则_目标管理:OKR与SMART原则的异同
  14. 推荐一个键盘快捷键库Mousetrap
  15. u-boot 之配置分析 (2)
  16. word如何一次将所有英文改为新罗马字体
  17. chromium 浏览器多进程架构小科普
  18. 火车采集器采集内容页分页教程
  19. 水下SLAM论文!!!
  20. APS 与 MES 的区别是什么?

热门文章

  1. 17、mysql中的存储过程的应用
  2. 面试了 N 个候选人后,我总结出这份 Java 面试准备技巧
  3. Hadoop入门(七)Mapreduce高级Shuffle
  4. mongodb如何实现更新一个字段的值为另外一个字段的值?
  5. Spring MVC常用注解,你会几个?
  6. sqlserver建库建表建约束,删库删表删约束的示例总结
  7. binarySearch与IndexOf的那些事儿~
  8. Hibernate基本概念 (2)
  9. 2018蓝桥杯省赛---java---A---7(三体攻击)
  10. java文件输入与输出_java文件输入和输出