日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

如何在OpenJDK中使用ECC

發(fā)布時(shí)間:2023/12/3 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何在OpenJDK中使用ECC 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

曾經(jīng)試圖在Java和OpenJDK中使用橢圓曲線密碼術(shù) (ECC)的每個(gè)人要么被迫使用Bouncy Castle,要么被SunEC提供者弄糊涂了 。 SunEC提供程序根據(jù)文檔 (報(bào)價(jià))提供以下算法:

AlgorithmParameters 歐共體
KeyAgreement ECDH
KeyFactory 歐共體
KeyPairGenerator 歐共體
Signature ECDSA沒有
SHA1withECDSA
SHA256withECDSA SHA3??84withECDSA SHA512withECDSA

不幸的是,OpenJDK并未附帶該提供程序。 但是任何真正想嘗試Java內(nèi)置ECC功能的人都可能會(huì)嘗試將sunec.jar(包含提供程序)簡單地添加到j(luò)re / lib / ext /文件夾中。 但是,當(dāng)嘗試使用提供程序時(shí),這些家伙一定會(huì)驚訝地擦著眼睛。 事情與剛開始時(shí)看起來不一樣...

假設(shè)我們將庫添加到了正確的文件夾中,我們的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”)運(yùn)行它,則會(huì)得到以下輸出:

KeyFactory: EC AlgorithmParameters: EC

哇! 這不是一個(gè)非常有用的提供程序.....承諾的算法在哪里? 讓我們嘗試使用Oracle JDK來運(yùn)行代碼,只是為了好玩:

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

驚喜,驚喜! 那是您開始揉眼睛的時(shí)刻! 這里是算法,但是為什么僅在使用Oracle JDK時(shí)才可用?

這樣做的原因隱藏在提供程序的代碼中。 以下幾行摘自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類中找到以下內(nèi)容:

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

好的,這說明了行為。 僅當(dāng)可以成功加載本機(jī)庫(Windows計(jì)算機(jī)上的libsunec.so或sunec.dll)時(shí),才存在算法。 在我們的情況下,顯然缺少該庫(因?yàn)槲覀儍H復(fù)制了sunec.jar文件)。

不幸的是,如果我們閱讀了提供者文檔,我們將了解以下內(nèi)容:

“ […] Java類打包到JRE擴(kuò)展目錄中已簽名的sunec.jar中,而C ++和C函數(shù)打包到JRE本機(jī)庫目錄中的libsunec.so或sunec.dll中。 如果不存在本機(jī)庫,則該提供者已注冊為支持較少的ECC算法(省略了KeyPairGenerator,Signature和KeyAgreement)。”

不幸的是,這是我們自己急于采取的行動(dòng),這浪費(fèi)了我們寶貴的開發(fā)時(shí)間。 摘自:有時(shí)候閱讀JavaDocs確實(shí)很有幫助……。 (但不像調(diào)試工作那樣富有教育意義)。

參考: Java安全和相關(guān)主題博客中的JCG合作伙伴 Christopher Meyer的如何將ECC與OpenJDK結(jié)合使用 。

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

總結(jié)

以上是生活随笔為你收集整理的如何在OpenJDK中使用ECC的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。