1 7 8 package org.enhydra.oyster.test; 9 10 import org.enhydra.oyster.smime.SignedSMIME; 11 import org.enhydra.oyster.exception.SMIMEException; 12 import javax.mail.Transport ; 13 import java.io.FileInputStream ; 14 import java.io.File ; 15 16 38 public class TestSigned 39 { 40 41 public static void main(String [] args) 42 { 43 String subject = "S/MIME signed message - Subject test: ÜüÄäÖöÜüß"; 44 String content = "S/MIME signed message example\r\nContent test: ÜüÄäÖöÜüß!"; 45 String from = "sender@together.at"; 46 String password = "together"; 47 48 if (args.length < 7) 49 { 50 System.err.println( 51 System.getProperty("line.separator") + 52 "Usage of TestSigned: " + 53 System.getProperty("line.separator") + 54 "java TestSigned <mailHost> <mailAddress> <digestAlgorithm> " + 55 "<includingCert> <includingSignAttrib> <pfxFileName> <externalSigning>" + 56 "[<attachment>]" + 57 System.getProperty("line.separator") + 58 System.getProperty("line.separator") + 59 "Examples:" + 60 System.getProperty("line.separator") + 61 "java TestSigned together.at recipient@together.at SHA1_WITH_RSA true " + 62 "true sender512.pfx true"+ 63 System.getProperty("line.separator") + 64 "java TestSigned together.at recipient@together.at SHA1_WITH_DSA true " + 65 "true senderDSA512.pfx false .\\test\\Zip8Test.zip"); 66 System.exit(-1); 67 } 68 69 String smtpHost = args[0]; 70 String addressTO = args[1]; 71 String digestAlgorithm = args[2]; 72 73 boolean includingCert = true; 74 if (args[3].equalsIgnoreCase("true")) 75 includingCert = true; 76 else 77 includingCert = false; 78 79 boolean includingSignAttrib = true; 80 if (args[4].equalsIgnoreCase("true")) 81 includingSignAttrib = true; 82 else 83 includingSignAttrib = false; 84 85 String pfxfileName = args[5]; 86 87 boolean externalSigning = true; 88 if (args[6].equalsIgnoreCase("true")) 89 externalSigning = true; 90 else 91 externalSigning = false; 92 93 String fileName = null; 94 if (args.length > 7) 95 fileName = args[7]; 96 97 String addressCC = "recipient@together.at"; 98 String addressBCC = "recipient@together.at"; 99 100 subject = digestAlgorithm + " " + args[3] + " " + args[4] + " " + 101 pfxfileName + " " + args[6] + " " + subject; 102 103 SignedSMIME ss = null; 104 105 try { 106 107 ss = new SignedSMIME(smtpHost, from, subject, content, "ISO-8859-1"); 109 110 if (fileName!=null) { 111 ss.addAttachment(fileName); } 113 114 ss.setReply(from); 116 ss.addRecipient(addressTO, "TO"); 120 ss.setCapabilities("SYMMETRIC", 5, 3, 1, 4, 2); ss.setCapabilities("ENCIPHER", 1, 0, 0, 0, 0); ss.setCapabilities("SIGNATURE", 1, 2, 3, 4, 0); 124 ss.addSigner(pfxfileName, password, digestAlgorithm, 125 includingCert, includingSignAttrib); 127 System.out.println("Creating signed message with " + digestAlgorithm + " algorithm ... "); 128 ss.signing(externalSigning); 129 System.out.print("Sending signed message ... "); 130 ss.send(); System.out.println("done."); 133 } 134 catch (Exception e) { 135 SMIMEException.setErrorFilePath("Log"); if(e instanceof SMIMEException) { 137 SMIMEException eTmp = (SMIMEException)e; 138 eTmp.displayErrors(null); 140 e = eTmp.getNonSMIMEException(); 141 if(e != null) 142 e.printStackTrace(); 143 } 144 else { 145 e.printStackTrace(); 146 } 147 } 148 } 149 } | Popular Tags |