Source Code Cross Referenced for DERObjectIdentifier.java in  » Web-Mail » oyster » org » enhydra » oyster » der » 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.der 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Title:        Oyster Project
003:         * Description:  S/MIME email sending capabilities
004:         * @Author       Vladimir Radisic
005:         * @Version      2.1.6
006:         */
007:
008:        package org.enhydra.oyster.der;
009:
010:        import org.enhydra.oyster.exception.SMIMEException;
011:        import org.enhydra.oyster.exception.ErrorStorage;
012:
013:        /**
014:         * DERObjectIdentifier is primitive type of DER encoded object which represents
015:         * Object Identifier type in ASN.1 notation. A value (distinguishable from all
016:         * other such values) which is associated with an information object. For
017:         * example object identifier for RSA algorithm is 1.2.840.113549.1.1.1.
018:         * Implemented object identifiers are stored in class IdentifierStorage.
019:         */
020:        public class DERObjectIdentifier extends DERObject {
021:
022:            /**
023:             * This constructor has two different forms, depend on parameter typeConstruction0,
024:             * which can be: DOT_SEPARATED_ARRAY or NAME_STRING. If typeConstruction0 parameter
025:             * is DOT_SEPARATED_ARRAY then id0 definition is represented by numbers separated
026:             * with dots (example: "1.2.840.113549.1.1.1"). In the case of NAME_STRING, id0
027:             * definition is name of object identifier (example: "RSA").
028:             * @param id0 defines Object Identifier in representation determined by the
029:             * second parameter - typeConstruction0.
030:             * @param typeConstruction0 can take values DOT_SEPARATED_ARRAY and NAME_STRING
031:             * @exception SMIMEException if wrong type of parameters are passed to the
032:             * constructor. Also, exception could be thrown in super class constructor or
033:             * in super class addContent method.
034:             */
035:            public DERObjectIdentifier(String id0, String typeConstruction0)
036:                    throws SMIMEException {
037:                super (6);
038:                byte[] contentID; // For storing content of ID identifiers byte string
039:                if (typeConstruction0.equalsIgnoreCase("DOT_SEPARATED_ARRAY")) // Construction with dot separated string of numbers
040:                {
041:                    int[] temp;
042:                    int[] dotPosition;
043:                    int j = -1, i = 0;
044:                    do // Counting number of dots to find out how many integers will contain Object Identificator string
045:                    {
046:                        j = id0.indexOf('.', j + 1);
047:                        i++;
048:                    } while (j != -1);
049:                    if (i == 1)
050:                        throw new SMIMEException(1008);
051:                    temp = new int[i];
052:                    dotPosition = new int[i - 1];
053:                    i = 0;
054:                    j = -1;
055:                    do // Filling dot position
056:                    {
057:                        j = id0.indexOf('.', j + 1);
058:                        if (j != -1)
059:                            dotPosition[i] = j;
060:                        i++;
061:                    } while (j != -1);
062:                    temp[0] = Integer.decode(id0.substring(0, dotPosition[0]))
063:                            .intValue(); // First number in Identificator object string
064:                    temp[temp.length - 1] = Integer
065:                            .decode(
066:                                    id0
067:                                            .substring(dotPosition[dotPosition.length - 1] + 1))
068:                            .intValue(); // Last number in Identificator object string
069:                    for (i = 1; i != temp.length - 1; i++)
070:                        temp[i] = Integer.decode(
071:                                id0.substring(dotPosition[i - 1] + 1,
072:                                        dotPosition[i])).intValue(); // Numbers between first and last number in Identificator object string
073:                    contentID = formatID(temp);
074:                    super .addContent(contentID); // Formating DER value of Object identificator
075:                } else if (typeConstruction0.equalsIgnoreCase("NAME_STRING")) {
076:                    contentID = formatID(IdentifierStorage.getID(id0
077:                            .toUpperCase()));
078:                    super .addContent(contentID); // Formating DER value of Object identificator
079:                } else
080:                    throw new SMIMEException(1009);
081:            }
082:
083:            /**
084:             * Array of numbers is used for construction of DERObjectIdentifier. Every number in
085:             * array represents one number between dots in the object identifier string.
086:             * @param arrayID0 array of given numbers (example: for RSA algorithm those
087:             * numbers are 1, 2, 840, 113549, 1, 1, and 1).
088:             * @exception SMIMEException if wrong type of parameters are passed to the
089:             * constructor. Also, exception could be thrown in super class constructor or
090:             * in super class addContent method.
091:             */
092:            public DERObjectIdentifier(int[] arrayID0) throws SMIMEException {
093:                super (6);
094:                super .addContent(formatID(arrayID0));
095:            }
096:
097:            /**
098:             * Creats Object Identifier octet string from discret number identifiers
099:             * @param id0 array of defined numbers for defined Object Identifier
100:             * @return Byte array representation of the DER encoded content of the Object
101:             * Identifier
102:             * @exception SMIMEException in case that unknown type of object identifier is
103:             * submited to constructors dealing with DOT_SEPARATED_ARRAY and NAME_STRING.
104:             * Also, it can be caused by non SMIMEException which is:
105:             * UnsupportedEncodingException.
106:             */
107:            private byte[] formatID(int[] id0) throws SMIMEException {
108:                int[] temp = new int[id0.length - 1];
109:                String s = new String();
110:                byte[] returnByteArray = null;
111:                if (id0[0] == -1)
112:                    throw new SMIMEException(1010);
113:                temp[0] = 40 * id0[0] + id0[1]; // First byte is constructed from the first and second discret numbers (that`s a rule)
114:                for (int i = 2; i != id0.length; i++)
115:                    temp[i - 1] = id0[i];
116:                try {
117:                    for (int i = 0; i != temp.length; i++) {
118:                        int j = 1; // j: Number of required bits for particular element of array "temp"
119:                        for (int a = 1; (a * 2) <= temp[i]; j++)
120:                            // Counting number of required bits
121:                            a = a * 2;
122:                        j = (int) Math.ceil((double) j / 7); // j: Number of required bytes for particular element of array "temp"
123:                        byte[] tempElement = new byte[j];
124:                        for (j = tempElement.length - 1; j >= 0; j--) {
125:                            tempElement[j] = (byte) ((temp[i] >> (7 * (tempElement.length - 1 - j))) & 0x7F);
126:                            if (j != (tempElement.length - 1))
127:                                tempElement[j] = (byte) (tempElement[j] | (0x80));
128:                        }
129:                        s = s.concat(new String(tempElement, "ISO-8859-1"));
130:                    }
131:                    returnByteArray = s.getBytes("ISO-8859-1");
132:                } catch (Exception e) {
133:                    throw new SMIMEException(e);
134:                }
135:                return returnByteArray;
136:            }
137:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.