我試圖使用org.apache.ws.security.components.crypto.CryptoFactory
特別是CryptoFactory.getInstance(properties)
方法獲得org.apache.ws.security.components.crypto.Merlin
的實例。從文件實例化JavaKeyStore時遇到麻煩
這將consistantly拋出
java.lang.RuntimeException: org.apache.ws.security.components.crypto.Merlin cannot create instance
其evantually由
java.security.UnrecoverableKeyException: Password verification failed
上的密鑰庫文件中的口令引起的已檢查用keytool在命令行上是正確的。
密鑰庫通過以下方法生成:
這是在蝕,項目的根目錄。
測試applciation如下:
public class App {
public static void main(String[] args) throws CredentialException,
IOException {
System.out.println("Starting");
Properties p = new Properties();
p.setProperty("org.apache.ws.security.crypto.merlin.keystore.password",
"password");
p.setProperty("org.apache.ws.security.crypto.provider",
"org.apache.ws.security.components.crypto.Merlin");
p.setProperty("org.apache.ws.security.crypto.merlin.keystore.type",
"jks");
p.setProperty("org.apache.ws.security.crypto.merlin.file", "./testkeystore.jks");
Crypto crypto = CryptoFactory.getInstance(p);
System.out.println(" Complete ");
}
}
併產生以下異常:
Exception in thread "main" java.lang.RuntimeException: org.apache.ws.security.components.crypto.Merlin cannot create instance
at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:225)
at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:180)
at org.apache.ws.security.components.crypto.CryptoFactory.getInstance(CryptoFactory.java:73)
at com.restart.test.cryptotest2.App.main(App.java:22)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.apache.ws.security.components.crypto.CryptoFactory.loadClass(CryptoFactory.java:211)
... 3 more
Caused by: org.apache.ws.security.components.crypto.CredentialException: Failed to load credentials.
at org.apache.ws.security.components.crypto.AbstractCrypto.load(AbstractCrypto.java:174)
at org.apache.ws.security.components.crypto.AbstractCrypto.<init>(AbstractCrypto.java:135)
at org.apache.ws.security.components.crypto.Merlin.<init>(Merlin.java:71)
... 8 more
Caused by: java.io.IOException: Keystore was tampered with, or password was incorrect
at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:772)
at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:55)
at java.security.KeyStore.load(KeyStore.java:1214)
at org.apache.ws.security.components.crypto.AbstractCrypto.load(AbstractCrypto.java:168)
... 10 more
Caused by: java.security.UnrecoverableKeyException: Password verification failed
at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:770)
... 13 more
如cmd窗口指示被設置爲「口令」的口令,但所有帳戶應用程序拒絕它,我可以更改密碼使用keytool -storepasswd
沒有問題,所以我知道我提供的密碼是正確的;任何人都可以提出這裏可能會出錯嗎?我一直在努力調試這一整天失敗的一整天。
如果有任何額外的信息,我可以提供,請讓我知道。
編輯 -
的folloing Maven的依賴關係,需要建立這個測試:
<dependency>
<groupId>org.apache.ws.security</groupId>
<artifactId>wss4j</artifactId>
<version>1.5.8</version>
<scope>provided</scope>
</dependency>
只需使用Oracle JDK 1.6重複您的步驟,並且無任何錯誤地工作。也許你的密碼不正確,或者你試圖打開不同的密鑰庫?嘗試重新創建它並設置密鑰庫的絕對路徑。 – user1516873 2013-04-29 12:55:24
嗨用戶,在閱讀您的評論後,我建立它針對不同版本的JDK/JRE,它的工作原理是,在下載rt.java的源代碼並逐步通過後,我發現CryptoBase類實例化了兩個JavaKeyStores,第一個我的.jks文件)實例化,但第二個是'jre \ lib \ security>'中的'cacerts' keystore,它沒有導致失敗的'changeit'的默認密碼;我現在已經改變了jre keystore上的密碼,並且在我原來的jre/jdk中工作得很好。所以謝謝你確認這是一個配置.. – Waltzy 2013-04-29 14:14:06
...問題,而不是我的編碼問題。不過,我討厭我的代表浪費,所以如果你想寫一些類似的效果我可以授予你。 – Waltzy 2013-04-29 14:14:44