在vs做的项目怎么连接到网站,黄骅港,汽车用品东莞网站建设,上海雍熙网站建设openjdk 使用曾经试图在Java和OpenJDK中使用椭圆曲线密码术 #xff08;ECC#xff09;的每个人要么被迫使用Bouncy Castle#xff0c;要么被SunEC提供者弄糊涂了 。 SunEC提供程序根据文档 #xff08;报价#xff09;提供以下算法#xff1a; AlgorithmParameters 欧… openjdk 使用 曾经试图在Java和OpenJDK中使用椭圆曲线密码术 ECC的每个人要么被迫使用Bouncy Castle要么被SunEC提供者弄糊涂了 。 SunEC提供程序根据文档 报价提供以下算法 AlgorithmParameters 欧共体 KeyAgreement ECDH KeyFactory 欧共体 KeyPairGenerator 欧共体 Signature ECDSA没有 SHA1withECDSA SHA256withECDSA SHA384withECDSA 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.meyerrub.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());}}} 如果最终使用OpenJDKJava版本“ 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 {MapObject, Object map new HashMapObject, 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算法省略了KeyPairGeneratorSignature和KeyAgreement。” 不幸的是这是我们自己急于采取的行动这浪费了我们宝贵的开发时间。 摘自有时候阅读JavaDocs确实很有帮助……。 但不像调试工作那样富有教育意义。 参考 Java安全和相关主题博客中的JCG合作伙伴 Christopher Meyer的如何将ECC与OpenJDK结合使用 。 翻译自: https://www.javacodegeeks.com/2013/10/how-to-use-ecc-with-openjdk.htmlopenjdk 使用