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 TestSigEncHtml 41 { 42 43 public static void main(String [] args) 44 { 45 46 String subject = "S/MIME signed and enveloped message - Subject test: ÜüÄäÖöÜüß"; 47 String content = "S/MIME signed and enveloped message example\r\nContent test: ÜüÄäÖöÜüß!"; 48 String from = "sender@together.at"; 49 String password = "together"; 50 51 if (args.length < 8) 52 { 53 System.err.println( 54 System.getProperty("line.separator") + 55 "Usage of TestSigEncHtml: " + 56 System.getProperty("line.separator") + 57 "java TestSigEncHtml <mailHost> <mailAddress> <cerFileName> " + 58 "<algorithmName> <digestAlgorithm> <includingCert> <includingSignAttrib> " + 59 "<pfxFileName> [<attachment>]"+ 60 System.getProperty("line.separator") + 61 System.getProperty("line.separator") + 62 "Examples:" + 63 System.getProperty("line.separator") + 64 "java TestSigEncHtml together.at recipient@together.at recipient512.cer " + 65 "RC240 SHA1_WITH_RSA true true sender512.pfx" + 66 System.getProperty("line.separator") + 67 "java TestSigEncHtml together.at recipient@together.at recipient512.cer " + 68 "DES MD5_WITH_RSA true true sender512.pfx .\\test\\Zip8Test.zip"); 69 System.exit(-1); 70 } 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 see = null; 106 107 try { 108 see = new SignedAndEnvelopedSMIME(smtpHost, from, subject, "ISO-8859-1"); 110 111 see.setContent(htmlContent,"text/html"); 113 117 121 if (fileName!=null) { 122 see.addAttachment(fileName); } 124 125 see.setReply(from); 127 see.addRecipient(addressTO, "TO", cerFileName); 131 see.setCapabilities("SYMMETRIC", 5, 3, 1, 4, 2); see.setCapabilities("ENCIPHER", 1, 0, 0, 0, 0); see.setCapabilities("SIGNATURE", 3, 2, 1, 4, 0); 135 see.addSigner(pfxfileName, password, digestAlgorithm, includingCert, includingSignAttrib); 136 137 if (algorithmName.equals("RC240")) 138 { 139 System.out.println("Creating signed and encrypted message with RC2 - 40 bits algorithm... "); 140 see.signingAndEnveloping("SIGN_FIRST"); } 143 else if (algorithmName.equals("RC264")) 144 { 145 System.out.println("Creating signed and encrypted message with RC2 - 64 bits algorithm... "); 146 see.signingAndEnveloping(see.RC2_CBC, 64, "SIGN_FIRST"); } 148 else if (algorithmName.equals("RC2128")) 149 { 150 System.out.println("Creating signed and encrypted message with RC2 - 128 bits algorithm... "); 151 see.signingAndEnveloping(see.RC2_CBC, 128, "SIGN_FIRST"); } 153 else if (algorithmName.equals("DES")) 154 { 155 System.out.println("Creating signed and encrypted message with DES algorithm... "); 156 see.signingAndEnveloping(see.DES, 56, "SIGN_FIRST"); } 158 else if (algorithmName.equals("3DES")) 159 { 160 System.out.println("Creating signed and encrypted message with 3DES algorithm... "); 161 see.signingAndEnveloping(see.DES_EDE3_CBC, 192, "SIGN_FIRST"); } 163 164 System.out.print("Sending signed and encrypted message ... "); 165 see.send(); System.out.println("done."); 168 169 } 170 catch (Exception e) { 171 SMIMEException.setErrorFilePath("Log"); if(e instanceof SMIMEException) { 173 SMIMEException eTmp = (SMIMEException)e; 174 eTmp.displayErrors(null); 176 e = eTmp.getNonSMIMEException(); 177 if(e != null) 178 e.printStackTrace(); 179 } 180 else { 181 e.printStackTrace(); 182 } 183 } 184 } 185 } | Popular Tags |