AES加密時拋出java.security.InvalidKeyException: Illegal key size or def

來源:互聯網
上載者:User

標籤:

原文:AES加密時拋出java.security.InvalidKeyException: Illegal key size or def 

使用AES加密時,當密鑰大於128時,代碼會拋出

java.security.InvalidKeyException: Illegal key size or default parameters

Illegal key size or default parameters是指密鑰長度是受限制的,java運行時環境讀到的是受限的policy檔案。檔案位於${java_home}/jre/lib/security

這種限制是因為美國對軟體出口的控制。

 

解決辦法:

去掉這種限制需要下載Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files.網址如下。

下載包的readme.txt 有安裝說明。就是替換${java_home}/jre/lib/security/ 下面的local_policy.jar和US_export_policy.jar

jdk 5: http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-java-plat-419418.html#jce_policy-1.5.0-oth-JPR

jdk6: http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html


 

AES加密時拋出java.security.InvalidKeyException: Illegal key size or def

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.