久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

NoSuchAlgorithmException:算法 HmacSHA1 不可用

NoSuchAlgorithmException: Algorithm HmacSHA1 not available(NoSuchAlgorithmException:算法 HmacSHA1 不可用)
本文介紹了NoSuchAlgorithmException:算法 HmacSHA1 不可用的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

看java的下面一行:

Look at the following line of java:

Mac.getInstance("HmacSHA1");

如果我把它放在一個(gè)簡(jiǎn)單的測(cè)試程序中,它在我的服務(wù)器上運(yùn)行沒有問題.但是,如果我在容器中使用這條線,我會(huì)得到

If I put this in a simple test program, it runs without problems on my server. However, if I use this line in a container, I get

java.security.NoSuchAlgorithmException: Algorithm HmacSHA1 not available
  at javax.crypto.Mac.getInstance(DashoA13*..)

在這兩種情況下都使用相同的 JDK 安裝.

The same JDK installation is used in both cases.

在谷歌上搜索了一下之后,我通過做兩件事設(shè)法讓它工作:

After googling around a bit, I managed to get it to work by doing two things:

  1. $JAVA_HOME/jre/lib/ext中的sunjce_provider.jar復(fù)制到容器的lib目錄中.
  2. 將以下行添加到我的代碼中:

  1. Copying sunjce_provider.jar from $JAVA_HOME/jre/lib/ext to the lib directory of the container.
  2. Adding the following line to my code:

java.security.Security.addProvider(new com.sun.crypto.provider.SunJCE());

具體來說,這發(fā)生在我的 Apache James 郵件中,但我很漂亮確定這與 JVM 選項(xiàng)有關(guān).這里是啟動(dòng)腳本 它使用.

Specifically, this happens to me in an Apache James mailet, but I'm pretty sure this is has to do with JVM options. Here is the startup script that it uses.

雖然我最終得到了它的工作,但這個(gè)解決方案感覺太老套了,無法成為正確的解決方案.我將不勝感激對(duì)正在發(fā)生的事情的解釋,以及更適當(dāng)"的解決方案.

Although I got it to work in the end, the solution feels too hacked to be the right one. I would appreciate an explanation of what is going on, as well as a more "proper" solution.

相關(guān)問題:使用Java加密導(dǎo)致NoSuchAlgorithmException.但是,在這種情況下,我很確定應(yīng)該支持開箱即用的 HmacSHA1 算法.作為證據(jù),這在測(cè)試程序中沒有問題.

Related question: Using Java crypto leads to NoSuchAlgorithmException. However, in this case I'm pretty sure the HmacSHA1 algorithm should be supported out of the box. As evidence, this works without problems in a test program.

推薦答案

啟動(dòng)腳本將 java.ext.dirs 設(shè)置為其自己的目錄集(特定于應(yīng)用程序),但省略了"normal" 擴(kuò)展目錄 ($JAVA_HOME/jre/lib/ext/),它是 sunjce_provider.jar 所在的位置.這解釋了您的第一點(diǎn)(將 Jar 文件復(fù)制到 lib 目錄使其再次可見).這很容易復(fù)制.

The startup script sets the java.ext.dirs to its own set of directories (specific to the application) but omitting the "normal" extension directory ($JAVA_HOME/jre/lib/ext/) which is where sunjce_provider.jar resides. This explains your first point (copying the Jar file to the lib directory makes it visible again). This is easily reproduced.

至于第二點(diǎn),我認(rèn)為這是由于啟動(dòng)腳本使用 -Djava.security.policy 選項(xiàng)設(shè)置的策略文件所致.某些提供程序是否可用取決于策略文件.默認(rèn)策略文件使 SunJCE 提供程序可用,但由于啟動(dòng)腳本要求使用非默認(rèn)的自定義策略文件,因此一切正常.我建議你看看那個(gè)策略文件.

As for the second point, I think this is due the policy file that the startup script sets with the -Djava.security.policy option. Whether some providers are available or not depends on policy files. The default policy file makes the SunJCE provider available, but since the startup scripts mandates a non-default, custom policy file, then anything goes. I suggest you take a look at that policy file.

例如,在我的系統(tǒng)上(Ubuntu Linux,Ubuntu 打包的 Sun JVM 1.6.0_20),默認(rèn)策略文件在 /etc/java-6-sun/security/java.security 并包含(除其他外)以下幾行:

For instance, on my system (Ubuntu Linux, with Sun JVM 1.6.0_20 as packaged by Ubuntu), the default policy file is in /etc/java-6-sun/security/java.security and contains (among others) the following lines:

security.provider.1=sun.security.provider.Sun
security.provider.2=sun.security.rsa.SunRsaSign
security.provider.3=com.sun.net.ssl.internal.ssl.Provider
security.provider.4=com.sun.crypto.provider.SunJCE
security.provider.5=sun.security.jgss.SunProvider
security.provider.6=com.sun.security.sasl.Provider
security.provider.7=org.jcp.xml.dsig.internal.dom.XMLDSigRI
security.provider.8=sun.security.smartcardio.SunPCSC

它定義了默認(rèn)情況下應(yīng)該可用的提供程序.根據(jù)您的癥狀,我認(rèn)為自定義策略文件使 SunJCE 不可用,除非明確注冊(cè)(這是可以理解的,因?yàn)閱?dòng)腳本還刪除了對(duì)包含 SunJCE 的 Jar 文件的訪問......).

which define what providers should be available by default. From your symptoms, I think that the custom policy file made SunJCE unavailable unless explicitly registered (which is understandable since the startup script also removed the access to the Jar file containing SunJCE...).

這篇關(guān)于NoSuchAlgorithmException:算法 HmacSHA1 不可用的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Java Remove Duplicates from an Array?(Java從數(shù)組中刪除重復(fù)項(xiàng)?)
How to fix Invocation failed Unexpected Response from Server: Unauthorized in Android studio(如何修復(fù)調(diào)用失敗來自服務(wù)器的意外響應(yīng):在 Android 工作室中未經(jīng)授權(quán))
AES encryption, got extra trash characters in decrypted file(AES 加密,解密文件中有多余的垃圾字符)
AES Error: Given final block not properly padded(AES 錯(cuò)誤:給定的最終塊未正確填充)
Detecting incorrect key using AES/GCM in JAVA(在 JAVA 中使用 AES/GCM 檢測(cè)不正確的密鑰)
AES-256-CBC in Java(Java 中的 AES-256-CBC)
主站蜘蛛池模板: 国产精品1区2区3区 欧美 中文字幕 | 亚洲一区二区三区四区av | av网站在线播放 | 久久久久久国产一区二区三区 | 久久久久久久久综合 | 97精品超碰一区二区三区 | 777zyz色资源站在线观看 | 色资源站| 日韩在线免费视频 | 日韩精品免费 | 天堂网av在线| 精品国产乱码久久久久久闺蜜 | 国产精品视频久久久 | 欧美日韩a| 日韩在线不卡 | 久久99精品久久久久久琪琪 | 在线观看涩涩视频 | 日本一区二区高清不卡 | 亚洲一区二区三区在线 | 国产欧美精品区一区二区三区 | 国产成人免费视频 | 中文字幕在线一区二区三区 | 天天艹天天干天天 | 亚洲播放一区 | 日韩不卡在线观看 | 丁香婷婷久久久综合精品国产 | 我我色综合 | 免费成人在线网站 | 国产精品99久久久久久久久 | 亚洲精品电影 | 在线精品观看 | 成人毛片视频免费 | 中国美女一级黄色片 | 日韩一区在线播放 | 一级日批片 | 日韩视频免费看 | 成人在线视频免费看 | 韩日在线 | 国产成年人小视频 | 9999在线视频 | 欧美九九九 |