* @param secret
* @throws WSSecurityException
*/
public byte[] deriveKey(int length, byte[] secret) throws WSSecurityException {
try {
DerivationAlgorithm algo = AlgoFactory.getInstance(getAlgorithm());
byte[] labelBytes = null;
String label = getLabel();
if (label == null || label.length() == 0) {
labelBytes =
(ConversationConstants.DEFAULT_LABEL
+ ConversationConstants.DEFAULT_LABEL).getBytes("UTF-8");
} else {
labelBytes = label.getBytes("UTF-8");
}
byte[] nonce = Base64.decode(getNonce());
byte[] seed = new byte[labelBytes.length + nonce.length];
System.arraycopy(labelBytes, 0, seed, 0, labelBytes.length);
System.arraycopy(nonce, 0, seed, labelBytes.length, nonce.length);
if (length <= 0) {
length = getLength();
}
return algo.createKey(secret, seed, getOffset(), length);
} catch (Exception e) {
throw new WSSecurityException(
WSSecurityException.FAILURE, null, null, e
);