View Javadoc
1 /* 2 * Title: S/MIME Project 3 * Description: S/MIME email transport capabilities. 4 * @Author Vladan Obradovic 5 * @Version 2.0.1 6 */ 7 8 package org.webdocwf.util.smime.test; 9 10 11 import javax.mail.Transport; 12 import org.webdocwf.util.smime.smime.EnvelopedSMIME; 13 import org.webdocwf.util.smime.exception.SMIMEException; 14 import java.io.File; 15 import java.io.FileInputStream; 16 17 18 /*** 19 * Tests enveloping process. Encrypted text/html message with or 20 * withouth attachments can be sent by this test. This example is test for 21 * composing of email message content by html code which is given from the file 22 * system. To get help for this example type: 23 * "java org.webdocwf.util.smime.test.TestEncryptHtml" in command line. 24 * It is assumed that smime200tests.jar is in your classpath.<BR> 25 * <BR> 26 * Parameters passed to example are:<BR> 27 * <mailHost> <mailAddress> <cerFileName> <algorithmName> 28 * [<attachment>]<BR> 29 * <BR> 30 * <algorithmName> could be: RC240, RC264, RC2128, 3DES or 3DES<BR> 31 * <BR> 32 * Note that for this example email address "FROM" is fixed to: "sender@seateam.co.yu". 33 * You should change this values in source code of TestEncryptHtml.java in order 34 * to use them with other "FROM" address. 35 */ 36 public class TestEncryptHtml { 37 38 public static void main(String[] args) { 39 40 String subject = "S/MIME encrypted message - Subject test: ÜüÄäÖöÜüß"; 41 String from = "sender@seateam.co.yu"; 42 43 if (args.length < 4) { 44 System.err.println( 45 System.getProperty("line.separator") + 46 "Usage of TestEncryptHtml: " + 47 System.getProperty("line.separator") + 48 "java TestEncryptHtml <mailHost> <mailAddress> <cerFileName> " + 49 "<algorithmName> [<attachment>]" + 50 System.getProperty("line.separator") + 51 System.getProperty("line.separator") + 52 "Examples:" + 53 System.getProperty("line.separator") + 54 "java TestEncryptHtml seateam.co.yu recipient@seateam.co.yu " + 55 "recipient512.cer RC240 " + 56 System.getProperty("line.separator") + 57 "java TestEncryptHtml seateam.co.yu recipient@seateam.co.yu " + 58 "recipient512.cer DES .//test//Zip8Test.zip"); 59 System.exit(-1); 60 } 61 String smtpHost = args[0]; 62 String addressTO = args[1]; 63 String cerFileName = args[2]; 64 String algorithmName = args[3]; 65 String fileName = null; 66 67 if (args.length > 4) 68 fileName = args[4]; 69 70 String addressCC = "recipient@seateam.co.yu"; 71 String addressBCC = "recipient@seateam.co.yu"; 72 73 subject = algorithmName + " " + cerFileName + " " + subject; 74 75 File htmlContent = new File("./test/HtmlTest.html"); 76 77 EnvelopedSMIME es = null; 78 79 try { 80 es = new EnvelopedSMIME(smtpHost, from, subject); 81 82 es.setContent(htmlContent, "text/html"); 83 // To send messages content withouth resources from FileInputStream (or any 84 // other input stream) comment previous line and use following commented line 85 // es.setContent(new FileInputStream(htmlContent),"text/html"); 86 87 if (fileName != null) { 88 es.addAttachment(fileName); // optional - use this if send attachment 89 } 90 91 es.setReply(from); // optional 92 93 es.addRecipient(addressTO, "TO", cerFileName); // mandatory 94 // es.addRecipient(addressCC, "CC", cerFileName); // optional 95 // es.addRecipient(addressBCC, "BCC", cerFileName); // optional 96 97 if (algorithmName.equals("RC240")) { 98 System.out.println("Creating the encrypted message with RC2_CBC - 40 bits algorithm... "); 99 es.enveloping(); // instead of this next line could be used 100 // es.enveloping("RC2_CBC", 40); 101 } else if (algorithmName.equals("RC264")) { 102 System.out.println("Creating the encrypted message with RC2_CBC - 64 bits algorithm... "); 103 es.enveloping("RC2_CBC", 64); // send message with RC2 - 64 bits algorithm 104 } else if (algorithmName.equals("RC2128")) { 105 System.out.println("Creating the encrypted message with RC2_CBC - 128 bits algorithm... "); 106 es.enveloping("RC2_CBC", 128); // send message with RC2 - 128 bits algorithm 107 } else if (algorithmName.equals("DES")) { 108 System.out.println("Creating the encrypted message with DES algorithm... "); 109 es.enveloping("DES", 56); // send message with DES algorithm 110 } else if (algorithmName.equals("3DES")) { 111 System.out.println("Creating the encrypted message with DES_EDE3_CBC algorithm... "); 112 es.enveloping("DES_EDE3_CBC", 192); // send message with 3DES algorithm 113 } 114 System.out.print("Sending encrypted message ... "); 115 es.send(); // instead of this next line could be used 116 // Transport.send(es.getSignedMessage()); 117 System.out.println("done."); 118 119 } catch (Exception e) { 120 SMIMEException.setErrorFilePath("Log"); //specifies directory for logging 121 if (e instanceof SMIMEException) { 122 // ((SMIMEException)e).loggingErrors(null); //logging 123 ((SMIMEException) e).displayErrors(null); 124 } else 125 System.out.println(e.getMessage()); 126 } 127 } 128 129 } 130

This page was automatically generated by Maven