1 7 8 package org.enhydra.oyster.test; 9 10 import javax.mail.Transport ; 11 import org.enhydra.oyster.smime.EnvelopedSMIME; 12 import org.enhydra.oyster.exception.SMIMEException; 13 import java.io.File ; 14 import java.io.ByteArrayInputStream ; 15 import java.io.InputStream ; 16 17 37 public class TestEncryptGeneratedHtml 38 { 39 40 public static void main (String [] args) 41 { 42 43 String subject = "S/MIME encrypted message - Subject test: ÜüÄäÖöÜüß"; 44 String from = "sender@together.at"; 45 46 if (args.length < 4) 47 { 48 System.err.println( 49 System.getProperty("line.separator") + 50 "Usage of TestEncryptGeneratedHtml: " + 51 System.getProperty("line.separator") + 52 "java TestEncryptGeneratedHtml <mailHost> <mailAddress> <cerFileName> " + 53 "<algorithmName> [<attachment>]" + 54 System.getProperty("line.separator") + 55 System.getProperty("line.separator") + 56 "Examples:" + 57 System.getProperty("line.separator") + 58 "java TestEncryptGeneratedHtml together.at recipient@together.at " + 59 "recipient512.cer RC240 " + 60 System.getProperty("line.separator") + 61 "java TestEncryptGeneratedHtml together.at recipient@together.at " + 62 "recipient512.cer DES .\\test\\Zip8Test.zip"); 63 System.exit(-1); 64 } 65 String smtpHost = args[0]; 66 String addressTO = args[1]; 67 String cerFileName = args[2]; 68 String algorithmName = args[3]; 69 String fileName = null; 70 if (args.length > 4) 71 fileName = args[4]; 72 73 String addressCC = "recipient@together.at"; 74 String addressBCC = "recipient@together.at"; 75 76 subject = algorithmName + " " + cerFileName + " " + subject; 77 78 EnvelopedSMIME es = null; 79 80 try 81 { 82 ExampleGenerator generator = new ExampleGenerator(); 83 84 String green = "*****000generated.gif"; 89 90 File redFile = new File ("./test/pictures/red.gif"); 93 String red = redFile.getAbsoluteFile().getCanonicalPath(); 94 95 File blueFile = new File ("./test/pictures/blue.gif"); 98 String blue = "file:///" + blueFile.getAbsoluteFile().getCanonicalPath(); 99 blue = blue.replace('\\','/'); 100 101 String commonPath = new File ("./test/HtmlTest.html").getParent(); 108 109 generator.setResourceInExampleHtml("GREEN", green); 110 generator.setResourceInExampleHtml("RED", red); 111 generator.setResourceInExampleHtml("BLUE", blue); 112 113 InputStream [] in = {generator.getGifImage()}; 115 116 es = new EnvelopedSMIME(smtpHost, from, subject, "ISO-8859-1"); 118 119 es.setContent( generator.getHtmlString(), "text/html", commonPath, in ); 121 125 es.addAttachment(generator.getZipStream(), "test.zip"); 129 130 File attachment2 = new File ("./test/AdobeAcrobatTest.pdf"); 132 es.addAttachment(attachment2); 133 File attachment3 = new File ("./test/Word2000Test.doc"); 134 es.addAttachment(attachment3); 135 136 if (fileName!=null) { 137 es.addAttachment(fileName); } 139 140 es.setReply(from); 142 es.addRecipient(addressTO, "TO", cerFileName); 146 if (algorithmName.equals("RC240")) 147 { 148 System.out.println("Creating the encrypted message with RC2_CBC - 40 bits algorithm... "); 149 es.enveloping(); } 152 else if (algorithmName.equals("RC264")) 153 { 154 System.out.println("Creating the encrypted message with RC2_CBC - 64 bits algorithm... "); 155 es.enveloping(es.RC2_CBC, 64); } 157 else if (algorithmName.equals("RC2128")) 158 { 159 System.out.println("Creating the encrypted message with RC2_CBC - 128 bits algorithm... "); 160 es.enveloping(es.RC2_CBC, 128); } 162 else if (algorithmName.equals("DES")) 163 { 164 System.out.println("Creating the encrypted message with DES algorithm... "); 165 es.enveloping(es.DES, 56); } 167 else if (algorithmName.equals("3DES")) 168 { 169 System.out.println("Creating the encrypted message with DES_EDE3_CBC algorithm... "); 170 es.enveloping(es.DES_EDE3_CBC, 192); } 172 System.out.print("Sending encrypted message ... "); 173 es.send(); System.out.println("done."); 176 177 } 178 catch (Exception e) { 179 SMIMEException.setErrorFilePath("Log"); if(e instanceof SMIMEException) { 181 SMIMEException eTmp = (SMIMEException)e; 182 eTmp.displayErrors(null); 184 e = eTmp.getNonSMIMEException(); 185 if(e != null) 186 e.printStackTrace(); 187 } 188 else { 189 e.printStackTrace(); 190 } 191 } 192 } 193 194 } 195 196 197 198 | Popular Tags |