18
18
19
19
import java .io .IOException ;
20
20
import java .security .GeneralSecurityException ;
21
+ import java .security .Key ;
21
22
import java .security .KeyStore ;
22
23
import javax .crypto .SecretKey ;
23
24
import javax .security .auth .callback .UnsupportedCallbackException ;
@@ -51,7 +52,7 @@ public void setKeyStore(KeyStore keyStore) {
51
52
}
52
53
53
54
/**
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
55
56
* on private keys, and signing.
56
57
*/
57
58
public void setPrivateKeyPassword (String privateKeyPassword ) {
@@ -61,7 +62,7 @@ public void setPrivateKeyPassword(String privateKeyPassword) {
61
62
}
62
63
63
64
/**
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
65
66
* the private key password.
66
67
*
67
68
* @see #setPrivateKeyPassword(String)
@@ -88,15 +89,12 @@ protected void handleDecrypt(WSPasswordCallback callback) throws IOException, Un
88
89
protected void handleKeyName (WSPasswordCallback callback ) throws IOException , UnsupportedCallbackException {
89
90
try {
90
91
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 ());
97
95
}
98
96
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" );
100
98
}
101
99
}
102
100
catch (GeneralSecurityException ex ) {
0 commit comments