String iterate = token.getIterations();
if (iterate == null) {
throw new XWSSecurityException("Value of Iterations retrieved from UsernameToken is null");
}
int iterations = Integer.parseInt(iterate);
PasswordDerivedKey pdk = new PasswordDerivedKey();
SecretKey sKey = null;
byte[] verifySignature = null;
if ((purpose == Purpose.DECRYPT)) {
salt[0] = MessageConstants.VALUE_FOR_ENCRYPTION;
if (isSymmetric) {
try {
verifySignature = pdk.generate160BitKey(password, iterations, salt);
} catch (UnsupportedEncodingException ex) {
logger.log(Level.SEVERE, LogStringsMessages.WSS_1381_ERROR_GENERATING_160_BITKEY(), ex);
throw new XWSSecurityException("error during generating 160 bit key ");
}
untBinding.setSecretKey(verifySignature);
sKey = untBinding.getSecretKey(SecurityUtil.getSecretKeyAlgorithm(algo));
untBinding.setSecretKey(sKey);
wssContext.setUsernameTokenBinding(untBinding);
byte[] secretKey = untBinding.getSecretKey().getEncoded();
SecretKey key = pdk.generate16ByteKeyforEncryption(secretKey);
sKey = key;
} else {
byte[] decSignature = null;
try {
decSignature = pdk.generate160BitKey(password, iterations, salt);
} catch (UnsupportedEncodingException ex) {
logger.log(Level.SEVERE, LogStringsMessages.WSS_1381_ERROR_GENERATING_160_BITKEY(), ex);
throw new XWSSecurityException("error during generating 160 bit key ");
}
byte[] keyof128Bits = new byte[16];
for (int i = 0; i < 16; i++) {
keyof128Bits[i] = decSignature[i];
}
untBinding.setSecretKey(keyof128Bits);
sKey = untBinding.getSecretKey(SecurityUtil.getSecretKeyAlgorithm(algo));
untBinding.setSecretKey(sKey);
}
} else if (purpose == Purpose.VERIFY) {
salt[0] = MessageConstants.VALUE_FOR_SIGNATURE;
try {
verifySignature = pdk.generate160BitKey(password, iterations, salt);
} catch (UnsupportedEncodingException ex) {
logger.log(Level.SEVERE, LogStringsMessages.WSS_1381_ERROR_GENERATING_160_BITKEY(), ex);
throw new XWSSecurityException("error during generating 160 bit key ");
}
untBinding.setSecretKey(verifySignature);
sKey = untBinding.getSecretKey(SecurityUtil.getSecretKeyAlgorithm(algo));
untBinding.setSecretKey(sKey);
//return sKey;
} else {
//handles RequiredDerivedKeys case
salt[0] = MessageConstants.VALUE_FOR_ENCRYPTION;
byte[] key = null;
try {
key = pdk.generate160BitKey(password, iterations, salt);
} catch (UnsupportedEncodingException ex) {
logger.log(Level.SEVERE, LogStringsMessages.WSS_1381_ERROR_GENERATING_160_BITKEY(), ex);
throw new XWSSecurityException("error during generating 160 bit key ");
}
byte[] sKeyof16ByteLength = new byte[16];