【Java加密】(一)JCE配置密碼編譯演算法強度不受限授權的安裝__java

來源:互聯網
上載者:User

【前言】Java加解密系列,根據實際開發進度,不定期更新

【下載】在Oracle網站上搜尋, Unlimited Strength Jurisdiction Policy Files 這個關鍵字,然後按照所安裝的JDK版本選擇對應的授權檔案,比如我的是JDK8,就選擇了這個
【安裝】 下載完這個zip包後,裡面有兩個jar包和一個readme.txt檔案。
按照README.txt裡的說明進行安裝。注意區別開發環境用的JRE在JDK裡面,運行環境的JRE是單獨的環境。在我的Mac上,JRE是裝在JDK裡的,對應路徑是 /Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/jre


進入到授權檔案安裝的目錄下

/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/jre/lib/security能夠查看到預設是有local_policy.jar 和  US_export_policy.jar的,改個名字儲存一下。


然後複製壓縮包裡的檔案到/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/jre/lib/security目錄下,這樣就安裝完成了。


【驗證】

可以用下面的程式驗證一下

 public static void securityVerify() throws Exception {        byte[]     data = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };     // create a 64 bit secret key from raw bytes        SecretKey key64 = new SecretKeySpec(                   new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },                   "Blowfish");             // create a cipher and attempt to encrypt the data block with our key        Cipher     c = Cipher.getInstance("Blowfish/ECB/NoPadding");        c.init(Cipher.ENCRYPT_MODE, key64);        c.doFinal(data);        System.out.println("64 bit test: passed");             // create a 192 bit secret key from raw bytes        SecretKey key192 = new SecretKeySpec(                    new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,                                 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,                                 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 },                    "Blowfish");        // now try encrypting with the larger key        c.init(Cipher.ENCRYPT_MODE, key192);        c.doFinal(data);        System.out.println("192 bit test: passed");        System.out.println("Tests completed");    }

如果是預設配置,

返回類似

64 bit test: passedException in thread "main" java.lang.SecurityException:        Unsupported keysize or algorithm parameters        at javax.crypto.Cipher.init(...)        at chapter1.SimplePolicyTest.main(SimplePolicyTest.java:38)

如果是替換後,返回

64 bit test: passed192 bit test: passedTests completed



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.