import java.io.FileInputStream;
import org.w3c.dom.Document;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
public class WSSEncryptionSample {
public static void main ( String argv[] )
{
try {
FileInputStream br = new FileInputStream( "input.xml" );
String message = "";
int ch = 0;
while ( ( ch = br.read() ) != -1 )
message += (char)ch;
WSSMessage wssMessage = new WSSMessage ( message );
if ( wssMessage.getWSSDocument() != null )
{
System.out.println ( "The plain text WSS message is :\n" );
printDocument ( wssMessage.getWSSDocument() );
}//if
System.out.println ( "***************************************************" );
System.out.println ( );
System.out.println ( );
System.out.println ( );
ReferenceListOnlyToken refList = new ReferenceListOnlyToken(
"tourOperatorRSAKey",
"myKeyStorePass",
"myTourOperatorKey",
"EncryptedKeyWithReferenceList",
wssMessage
);
refList.setSecret ( new String ( "myKeyPass" ).getBytes() );
EncryptedData ed = wssMessage.encryptElement (
"Param3",
refList,
"encryptedParam3",
"http://www.w3.org/2001/04/xmlenc#rsa-1_5"
);
if ( ed.getDocument() != null )
{
System.out.println (
"The XML Encrypted Message with ReferenceListOnlyToken is :\n" );
printDocument ( ed.getDocument() );
}
System.out.println ( "***************************************************" );
System.out.println ( );
System.out.println ( );
System.out.println ( );
}//try
catch ( Exception e ) {
System.out.println ( "Exception in the main method of WSSEncryptionSample......." );
e.printStackTrace();
}//catch
}// main()
private static void printDocument ( Document XMLDoc ) {
try {
System.out.println();
OutputFormat f = new OutputFormat ( XMLDoc );
f.setPreserveSpace ( true );
XMLSerializer s = new XMLSerializer ( System.out, f );
s.serialize ( XMLDoc );
System.out.println();
}//try
catch ( Exception e ) {
System.out.println ( "Exception in printDocument's method of Encrypt Class......." );
e.printStackTrace();
}//catch
}//printDocument
}//WSSEncryptionSample