Document doc = unsignedEnvelope.getAsDocument();
WSSecHeader secHeader = new WSSecHeader();
secHeader.insertSecurityHeader(doc);
WSSecSecurityContextToken sctBuilder = new WSSecSecurityContextToken();
sctBuilder.prepare(doc, crypto);
sctBuilder.prependSCTElementToHeader(doc, secHeader);
String out = org.apache.ws.security.util.XMLUtils
.PrettyDocumentToString(doc);