1 7 8 package org.enhydra.oyster.test; 9 10 import javax.mail.Transport ; 11 import org.enhydra.oyster.smime.SignedAndEnvelopedSMIME; 12 import org.enhydra.oyster.exception.SMIMEException; 13 import java.io.FileInputStream ; 14 import java.io.File ; 15 16 40 public class TestEncSigHtml 41 { 42 43 public static void main(String [] args) 44 { 45 46 String subject = "S/MIME enveloped and signed message - Subject test: ÜüÄäÖöÜüß"; 47 String from = "sender@together.at"; 48 String password = "together"; 49 50 if (args.length < 8) 51 { 52 System.err.println( 53 System.getProperty("line.separator") + 54 "Usage of TestEncSigHtml: " + 55 System.getProperty("line.separator") + 56 "java TestEncSigHtml <mailHost> <mailAddress> <cerFileName> " + 57 "<algorithmName> <digestAlgorithm> <includingCert> <includingSignAttrib> " + 58 "<pfxFileName> [<attachment>]"+ 59 System.getProperty("line.separator") + 60 System.getProperty("line.separator") + 61 "Examples:" + 62 System.getProperty("line.separator") + 63 "java TestEncSigHtml together.at recipient@together.at recipient512.cer " + 64 "RC240 SHA1_WITH_RSA true true sender512.pfx" + 65 System.getProperty("line.separator") + 66 "java TestEncSigHtml together.at recipient@together.at recipient512.cer " + 67 "DES MD5_WITH_RSA true true sender512.pfx .\\test\\Zip8Test.zip"); 68 69 70 System.exit(-1); 71 } 72 73 String smtpHost = args[0]; 74 String addressTO = args[1]; 75 String cerFileName = args[2]; 76 String algorithmName = args[3]; 77 String digestAlgorithm = args[4]; 78 79 boolean includingCert = true; 80 if (args[5].equals("true")) 81 includingCert = true; 82 else 83 includingCert = false; 84 85 boolean includingSignAttrib = true; 86 if (args[6].equals("true")) 87 includingSignAttrib = true; 88 else 89 includingSignAttrib = false; 90 91 String pfxfileName = args[7]; 92 93 String fileName = null; 94 if (args.length > 8) 95 fileName = args[8]; 96 97 String addressCC = "recipient@together.at"; 98 String addressBCC = "recipient@together.at"; 99 100 subject = args[2] + " " + args[3] + " " + args[4] + " " + args[5] + " " + 101 args[6] + " " + args[7] + " " + subject; 102 103 File htmlContent = new File ("./test/HtmlTest.html"); 104 105 SignedAndEnvelopedSMIME ess = null; 106 107 try { 108 ess = new SignedAndEnvelopedSMIME(smtpHost, from, subject, "ISO-8859-1"); 110 111 ess.setContent(htmlContent,"text/html"); 112 116 120 if (fileName!=null) { 121 ess.addAttachment(fileName); } 123 124 ess.setReply(from); 126 ess.addRecipient(addressTO, "TO", cerFileName); 130 ess.setCapabilities("SYMMETRIC", 5, 3, 1, 4, 2); ess.setCapabilities("ENCIPHER", 1, 0, 0, 0, 0); ess.setCapabilities("SIGNATURE", 3, 2, 1, 4, 0); 134 ess.addSigner(pfxfileName, password, digestAlgorithm, includingCert, includingSignAttrib); 135 136 if (algorithmName.equals("RC240")) 137 { 138 System.out.println("Creating enveloped and signed message with RC2 - 40 bits algorithm... "); 139 ess.signingAndEnveloping("ENCRYPT_FIRST"); } 142 else if (algorithmName.equals("RC264")) 143 { 144 System.out.println("Creating enveloped and signed message with RC2 - 64 bits algorithm... "); 145 ess.signingAndEnveloping(ess.RC2_CBC, 64, "ENCRYPT_FIRST"); } 147 else if (algorithmName.equals("RC2128")) 148 { 149 System.out.println("Creating enveloped and signed message with RC2 - 128 bits algorithm... "); 150 ess.signingAndEnveloping(ess.RC2_CBC, 128, "ENCRYPT_FIRST"); } 152 else if (algorithmName.equals("DES")) 153 { 154 System.out.println("Creating enveloped and signed message with DES algorithm... "); 155 ess.signingAndEnveloping(ess.DES, 56, "ENCRYPT_FIRST"); } 157 else if (algorithmName.equals("3DES")) 158 { 159 System.out.println("Creating enveloped and signed message with 3DES algorithm... "); 160 ess.signingAndEnveloping(ess.DES_EDE3_CBC, 192, "ENCRYPT_FIRST"); } 162 163 System.out.print("Sending enveloped and signed message ... "); 164 ess.send(); System.out.println("done."); 167 168 } 169 catch (Exception e) { 170 SMIMEException.setErrorFilePath("Log"); if(e instanceof SMIMEException) { 172 SMIMEException eTmp = (SMIMEException)e; 173 eTmp.displayErrors(null); 175 e = eTmp.getNonSMIMEException(); 176 if(e != null) 177 e.printStackTrace(); 178 } 179 else { 180 e.printStackTrace(); 181 } 182 } 183 } 184 } | Popular Tags |