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.FileInputStream ; 15 16 34 public class TestEncryptHtml 35 { 36 37 public static void main (String [] args) 38 { 39 40 String subject = "S/MIME encrypted message - Subject test: ÜüÄäÖöÜüß"; 41 String from = "sender@together.at"; 42 43 if (args.length < 4) 44 { 45 System.err.println( 46 System.getProperty("line.separator") + 47 "Usage of TestEncryptHtml: " + 48 System.getProperty("line.separator") + 49 "java TestEncryptHtml <mailHost> <mailAddress> <cerFileName> " + 50 "<algorithmName> [<attachment>]" + 51 System.getProperty("line.separator") + 52 System.getProperty("line.separator") + 53 "Examples:" + 54 System.getProperty("line.separator") + 55 "java TestEncryptHtml together.at recipient@together.at " + 56 "recipient512.cer RC240 " + 57 System.getProperty("line.separator") + 58 "java TestEncryptHtml together.at recipient@together.at " + 59 "recipient512.cer DES .\\test\\Zip8Test.zip"); 60 System.exit(-1); 61 } 62 String smtpHost = args[0]; 63 String addressTO = args[1]; 64 String cerFileName = args[2]; 65 String algorithmName = args[3]; 66 String fileName = null; 67 if (args.length > 4) 68 fileName = args[4]; 69 70 String addressCC = "recipient@together.at"; 71 String addressBCC = "recipient@together.at"; 72 73 subject = algorithmName + " " + cerFileName + " " + subject; 74 75 File htmlContent = new File ("./test/HtmlTest.html"); 76 77 EnvelopedSMIME es = null; 78 79 try 80 { 81 es = new EnvelopedSMIME(smtpHost, from, subject, "ISO-8859-1"); 83 84 es.setContent(htmlContent,"text/html"); 86 90 94 if (fileName!=null) 95 { 96 es.addAttachment(fileName); } 98 99 es.setReply(from); 101 es.addRecipient(addressTO, "TO", cerFileName); 105 if (algorithmName.equals("RC240")) 106 { 107 System.out.println("Creating the encrypted message with RC2_CBC - 40 bits algorithm... "); 108 es.enveloping(); } 111 else if (algorithmName.equals("RC264")) 112 { 113 System.out.println("Creating the encrypted message with RC2_CBC - 64 bits algorithm... "); 114 es.enveloping(es.RC2_CBC, 64); } 116 else if (algorithmName.equals("RC2128")) 117 { 118 System.out.println("Creating the encrypted message with RC2_CBC - 128 bits algorithm... "); 119 es.enveloping(es.RC2_CBC, 128); } 121 else if (algorithmName.equals("DES")) 122 { 123 System.out.println("Creating the encrypted message with DES algorithm... "); 124 es.enveloping(es.DES, 56); } 126 else if (algorithmName.equals("3DES")) 127 { 128 System.out.println("Creating the encrypted message with DES_EDE3_CBC algorithm... "); 129 es.enveloping(es.DES_EDE3_CBC, 192); } 131 System.out.print("Sending encrypted message ... "); 132 es.send(); System.out.println("done."); 135 136 } 137 catch (Exception e) { 138 SMIMEException.setErrorFilePath("Log"); if(e instanceof SMIMEException) { 140 SMIMEException eTmp = (SMIMEException)e; 141 eTmp.displayErrors(null); 143 e = eTmp.getNonSMIMEException(); 144 if(e != null) 145 e.printStackTrace(); 146 } 147 else { 148 e.printStackTrace(); 149 } 150 } 151 } 152 153 } 154 155 156 157 | Popular Tags |