public EncryptedData createEncryptedData(String id, Attachment attachment, String dataAlgo, KeyInfoType keyInfo, Key key, EncryptionTarget target) {
AttachmentData attachData = new AttachmentData(attachment);
String cid = "cid:" + attachment.getContentId();
boolean contentOnly = target.getContentOnly();
EncryptedDataType edt = new EncryptedDataType();
if(contentOnly){
edt.setType(MessageConstants.SWA11_ATTACHMENT_CONTENT_ONLY);
}else{
edt.setType(MessageConstants.SWA11_ATTACHMENT_COMPLETE);
}
edt.setMimeType(attachment.getContentType());
EncryptionMethodType emt = new EncryptionMethodType();
emt.setAlgorithm(dataAlgo);
edt.setEncryptionMethod(emt);
CipherDataType ct = new CipherDataType();
CipherReferenceType crt = new CipherReferenceType();
crt.setURI(cid);
TransformsType tst = new TransformsType();
ArrayList<TransformType> ttList = new ArrayList<TransformType>();
ArrayList list = target.getCipherReferenceTransforms();
for(Object obj : list){
EncryptionTarget.Transform tr = (EncryptionTarget.Transform)obj;
TransformType tt = new TransformType();
tt.setAlgorithm(tr.getTransform());
ttList.add(tt);
}
if(!ttList.isEmpty()){
tst.setTransform(ttList);
}
crt.setTransforms(tst);
ct.setCipherReference(crt);
edt.setCipherData(ct);
edt.setId(id);
if(keyInfo != null){
edt.setKeyInfo(keyInfo);
}
return new JAXBEncryptedData(edt,attachData,key,soapVersion);
}