1818
1919import java .io .IOException ;
2020import java .security .GeneralSecurityException ;
21+ import java .security .Key ;
2122import java .security .KeyStore ;
2223import javax .crypto .SecretKey ;
2324import javax .security .auth .callback .UnsupportedCallbackException ;
@@ -51,7 +52,7 @@ public void setKeyStore(KeyStore keyStore) {
5152 }
5253
5354 /**
54- * Sets the password used to retrieve private keys from the keystore. This property is required for decription based
55+ * Sets the password used to retrieve private keys from the keystore. This property is required for decryption based
5556 * on private keys, and signing.
5657 */
5758 public void setPrivateKeyPassword (String privateKeyPassword ) {
@@ -61,7 +62,7 @@ public void setPrivateKeyPassword(String privateKeyPassword) {
6162 }
6263
6364 /**
64- * Sets the password used to retrieve keys from the symmetric keystore. If this property is not set, it default to
65+ * Sets the password used to retrieve keys from the symmetric keystore. If this property is not set, it defaults to
6566 * the private key password.
6667 *
6768 * @see #setPrivateKeyPassword(String)
@@ -88,15 +89,12 @@ protected void handleDecrypt(WSPasswordCallback callback) throws IOException, Un
8889 protected void handleKeyName (WSPasswordCallback callback ) throws IOException , UnsupportedCallbackException {
8990 try {
9091 String identifier = callback .getIdentifer ();
91- KeyStore .PasswordProtection protection = new KeyStore .PasswordProtection (symmetricKeyPassword );
92- KeyStore .Entry entry = keyStore .getEntry (identifier , protection );
93- if (entry instanceof KeyStore .SecretKeyEntry ) {
94- KeyStore .SecretKeyEntry secretKeyEntry = (KeyStore .SecretKeyEntry ) entry ;
95- SecretKey secretKey = secretKeyEntry .getSecretKey ();
96- callback .setKey (secretKey .getEncoded ());
92+ Key key = keyStore .getKey (identifier , symmetricKeyPassword );
93+ if (key instanceof SecretKey ) {
94+ callback .setKey (key .getEncoded ());
9795 }
9896 else {
99- throw new WSSecurityException ("Key entry [" + entry + "] is not a javax.crypto.SecretKey" );
97+ throw new WSSecurityException ("Key [" + key + "] is not a javax.crypto.SecretKey" );
10098 }
10199 }
102100 catch (GeneralSecurityException ex ) {
0 commit comments