Source Code Cross Referenced for TestEncSig.java in  » Web-Mail » oyster » org » enhydra » oyster » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Mail » oyster » org.enhydra.oyster.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Title:        Oyster Project
003:         * Description:  S/MIME email sending capabilities
004:         * @Author       Vladan Obradovic, Vladimir Radisic
005:         * @Version      2.1.6
006:         */
007:
008:        package org.enhydra.oyster.test;
009:
010:        import org.enhydra.oyster.cms.consts.CapabilitiesConstants;
011:        import javax.mail.Transport;
012:        import org.enhydra.oyster.smime.SignedAndEnvelopedSMIME;
013:        import org.enhydra.oyster.exception.SMIMEException;
014:
015:        /**
016:         * Tests enveloping and signing process. Enveloped and signed
017:         * text/plain message with or withouth attachments can be sent by this test.
018:         * To get help for this example type: "java org.enhydra.oyster.test.TestEncSig"
019:         * in command line. It is assumed that oyster_tests.jar is in your classpath.<BR>
020:         * <BR>
021:         * Parameters passed to example are:<BR>
022:         * &lt;mailHost&gt; &lt;mailAddress&gt; &lt;cerFileName&gt; &lt;algorithmName&gt;
023:         * &lt;digestAlgorithm&gt; &lt;includingCert&gt; &lt;includingSignAttrib&gt;
024:         * &lt;pfxFileName&gt; [&lt;attachment&gt;] <BR>
025:         * <BR>
026:         * &lt;digestAlgorithm&gt; could be: SHA1_WITH_RSA, MD2_WITH_RSA, MD5_WITH_RSA or SHA1_WITH_DSA.<BR>
027:         * &lt;includingCert&gt; could be: true/false<BR>
028:         * &lt;includingSignAttrib&gt; could be: true/false<BR>
029:         * &lt;algorithmName&gt; could be: RC240, RC264, RC2128, 3DES or 3DES<BR>
030:         * <BR>
031:         * Note that for this example's passwords for .pfx or .p12 files are fixed to
032:         * "together". All .pfx files or .p12 files provided with this example have this
033:         * password. Also, email address "FROM" is fixed to: "sender@together.at".
034:         * You should change this values in source code of TestEncSig.java in order to use
035:         * them with other .pfx or .p12 files and corresponding "FROM" addresses and passwords.
036:         */
037:        public class TestEncSig {
038:
039:            public static void main(String[] args) {
040:
041:                String subject = "S/MIME enveloped and signed message - Subject test: ÜüÄäÖöÜüß";
042:                String content = "S/MIME enveloped and signed message example\r\nContent test: ÜüÄäÖöÜüß!";
043:                String from = "sender@together.at";
044:                String password = "together";
045:
046:                if (args.length < 8) {
047:                    System.err
048:                            .println(System.getProperty("line.separator")
049:                                    + "Usage of TestEncSig: "
050:                                    + System.getProperty("line.separator")
051:                                    + "java TestEncSig <mailHost> <mailAddress> <cerFileName> "
052:                                    + "<algorithmName> <digestAlgorithm> <includingCert> <includingSignAttrib> "
053:                                    + "<pfxFileName> [<attachment>]"
054:                                    + System.getProperty("line.separator")
055:                                    + System.getProperty("line.separator")
056:                                    + "Examples:"
057:                                    + System.getProperty("line.separator")
058:                                    + "java TestEncSig together.at recipient@together.at recipient512.cer "
059:                                    + "RC240 SHA1_WITH_RSA true true sender512.pfx"
060:                                    + System.getProperty("line.separator")
061:                                    + "java TestEncSig together.at recipient@together.at recipient512.cer "
062:                                    + "DES MD5_WITH_RSA true true sender512.pfx .\\test\\Zip8Test.zip");
063:
064:                    System.exit(-1);
065:                }
066:
067:                String smtpHost = args[0];
068:                String addressTO = args[1];
069:                String cerFileName = args[2];
070:                String algorithmName = args[3];
071:                String digestAlgorithm = args[4];
072:
073:                boolean includingCert = true;
074:                if (args[5].equals("true"))
075:                    includingCert = true;
076:                else
077:                    includingCert = false;
078:
079:                boolean includingSignAttrib = true;
080:                if (args[6].equals("true"))
081:                    includingSignAttrib = true;
082:                else
083:                    includingSignAttrib = false;
084:
085:                String pfxfileName = args[7];
086:
087:                String fileName = null;
088:                if (args.length > 8)
089:                    fileName = args[8];
090:
091:                String addressCC = "recipient@together.at";
092:                String addressBCC = "recipient@together.at";
093:
094:                subject = args[2] + " " + args[3] + " " + args[4] + " "
095:                        + args[5] + " " + args[6] + " " + args[7] + " "
096:                        + subject;
097:
098:                SignedAndEnvelopedSMIME ess = null;
099:
100:                try {
101:                    // Construction of enveloped and signed smime object
102:                    ess = new SignedAndEnvelopedSMIME(smtpHost, from, subject,
103:                            content, "ISO-8859-1");
104:
105:                    if (fileName != null) {
106:                        ess.addAttachment(fileName); // optional - use this if send attachment
107:                    }
108:
109:                    ess.setReply(from); // optional
110:
111:                    ess.addRecipient(addressTO, "TO", cerFileName); // mandatory
112:                    //      ess.addRecipient(addressCC, "CC", cerFileName); // optional
113:                    //      ess.addRecipient(addressBCC, "BCC", cerFileName); // optional
114:
115:                    ess.setCapabilities(CapabilitiesConstants.SYMMETRIC,
116:                            new String[] { CapabilitiesConstants.DES_EDE3_CBC,
117:                                    CapabilitiesConstants.RC2_CBC_128,
118:                                    CapabilitiesConstants.RC2_CBC_40,
119:                                    CapabilitiesConstants.DES,
120:                                    CapabilitiesConstants.RC2_CBC_64 }); // optional
121:                    ess.setCapabilities(CapabilitiesConstants.ENCIPHER,
122:                            new String[] { CapabilitiesConstants.RSA }); // optional
123:                    ess.setCapabilities(CapabilitiesConstants.SIGNATURE,
124:                            new String[] { CapabilitiesConstants.SHA1_WITH_RSA,
125:                                    CapabilitiesConstants.MD5_WITH_RSA,
126:                                    CapabilitiesConstants.MD2_WITH_RSA,
127:                                    CapabilitiesConstants.SHA1_WITH_DSA }); // optional
128:
129:                    ess.addSigner(pfxfileName, password, digestAlgorithm,
130:                            includingCert, includingSignAttrib);
131:
132:                    if (algorithmName.equals("RC240")) {
133:                        System.out
134:                                .println("Creating enveloped and signed message with RC2 - 40 bits algorithm... ");
135:                        ess.signingAndEnveloping("ENCRYPT_FIRST"); // instead of this next line could be used
136:                        //        ess.enveloping(ess.RC2_CBC, 40, "ENCRYPT_FIRST");
137:                    } else if (algorithmName.equals("RC264")) {
138:                        System.out
139:                                .println("Creating enveloped and signed message with RC2 - 64 bits algorithm... ");
140:                        ess.signingAndEnveloping(ess.RC2_CBC, 64,
141:                                "ENCRYPT_FIRST"); // send message with RC2 - 64 bits algorithm
142:                    } else if (algorithmName.equals("RC2128")) {
143:                        System.out
144:                                .println("Creating enveloped and signed message with RC2 - 128 bits algorithm... ");
145:                        ess.signingAndEnveloping(ess.RC2_CBC, 128,
146:                                "ENCRYPT_FIRST"); // send message with RC2 - 128 bits algorithm
147:                    } else if (algorithmName.equals("DES")) {
148:                        System.out
149:                                .println("Creating enveloped and signed message with DES algorithm... ");
150:                        ess.signingAndEnveloping(ess.DES, 56, "ENCRYPT_FIRST"); // send message with DES - 56 bits algorithm
151:                    } else if (algorithmName.equals("3DES")) {
152:                        System.out
153:                                .println("Creating enveloped and signed message with 3DES algorithm... ");
154:                        ess.signingAndEnveloping(ess.DES_EDE3_CBC, 192,
155:                                "ENCRYPT_FIRST"); // send message with 3DES - 192 bits algorithm
156:                    }
157:
158:                    System.out
159:                            .print("Sending enveloped and signed message ... ");
160:                    ess.send(); // instead of this next line could be used
161:                    //      Transport.send(ess.getSignedMessage());
162:                    System.out.println("done.");
163:
164:                } catch (Exception e) {
165:                    e.printStackTrace();
166:                }
167:            }
168:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.