public List getObjects() {
return null;
}
public void sign(XMLSignContext xMLSignContext) throws MarshalException, XMLSignatureException {
SignatureMethod sm;
if (xMLSignContext == null) {
throw new NullPointerException("signContext cannot be null");
}
//List allReferences = new ArrayList(signedInfo.getReferences());
SignedInfo si = getSignedInfo();
List refList = si.getReferences();
for (int i = 0, size = refList.size(); i < size; i++) {
Reference ref = (Reference) refList.get(i);
ref.digest(xMLSignContext);
}
Key signingKey = null;
KeySelectorResult keySelectoResult = null;
try {
sm = si.getSignatureMethod();
keySelectoResult = xMLSignContext.getKeySelector().select(getKeyInfo(),KeySelector.Purpose.SIGN,sm,xMLSignContext);
signingKey = keySelectoResult.getKey();
if (signingKey == null) {
throw new XMLSignatureException("The KeySelector"+ xMLSignContext.getKeySelector()+ " did not " +
"find the key used for signing");
}
} catch (KeySelectorException kse) {
throw new XMLSignatureException("Cannot find signing key", kse);
}
if(_sp == null){
try {
JAXBContext jc = JAXBUtil.getJAXBContext();
_sp = new SignatureProcessor();
_sp.setJAXBContext(jc);
_sp.setCryptoContext(xMLSignContext);
} catch (Exception ex) {
throw new XMLSignatureException(ex);
}
}
String signatureAlgo = sm.getAlgorithm();
//SignatureValue sv=getSignatureValue();
String algo = getRSASignatureAlgorithm(signatureAlgo);
if(algo != null){
try {
com.sun.xml.ws.security.opt.crypto.dsig.SignatureValue sigValue = new com.sun.xml.ws.security.opt.crypto.dsig.SignatureValue();
sigValue.setValue(_sp.performRSASign(signingKey,signedInfo,algo));
setSignatureValue(sigValue);
//((SignatureValueType)getSignatureValue()).setValue(_sp.performRSASign(signingKey,signedInfo));
//((SignatureValueType)sv).setValue(_sp.performRSASign(signingKey,signedInfo));
} catch (InvalidKeyException ex) {
throw new XMLSignatureException(ex);
}
} else if(signatureAlgo.equals(SignatureMethod.DSA_SHA1)){
try {
com.sun.xml.ws.security.opt.crypto.dsig.SignatureValue sigValue = new com.sun.xml.ws.security.opt.crypto.dsig.SignatureValue();
sigValue.setValue(_sp.performDSASign(signingKey,signedInfo));
setSignatureValue(sigValue);
//((SignatureValueType)sv).setValue(_sp.performDSASign(signingKey,signedInfo));
} catch (InvalidKeyException ex) {
throw new XMLSignatureException(ex);
}
} else if ( signatureAlgo.equals(SignatureMethod.HMAC_SHA1)) {
SignatureMethodParameterSpec params = (SignatureMethodParameterSpec)sm.getParameterSpec();
int outputLength = -1;
if (params != null) {
if (!(params instanceof HMACParameterSpec)) {
throw new XMLSignatureException
("SignatureMethodParameterSpec must be of type HMACParameterSpec");