Source Code Cross Referenced for X509NameEntryConverter.java in  » Security » Bouncy-Castle » org » bouncycastle » asn1 » x509 » 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 » Security » Bouncy Castle » org.bouncycastle.asn1.x509 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.bouncycastle.asn1.x509;
002:
003:        import org.bouncycastle.asn1.ASN1InputStream;
004:        import org.bouncycastle.asn1.DERObject;
005:        import org.bouncycastle.asn1.DERObjectIdentifier;
006:        import org.bouncycastle.asn1.DERPrintableString;
007:        import org.bouncycastle.util.Strings;
008:
009:        import java.io.IOException;
010:
011:        /**
012:         * It turns out that the number of standard ways the fields in a DN should be 
013:         * encoded into their ASN.1 counterparts is rapidly approaching the
014:         * number of machines on the internet. By default the X509Name class 
015:         * will produce UTF8Strings in line with the current recommendations (RFC 3280).
016:         * <p>
017:         * An example of an encoder look like below:
018:         * <pre>
019:         * public class X509DirEntryConverter
020:         *     extends X509NameEntryConverter
021:         * {
022:         *     public DERObject getConvertedValue(
023:         *         DERObjectIdentifier  oid,
024:         *         String               value)
025:         *     {
026:         *         if (str.length() != 0 && str.charAt(0) == '#')
027:         *         {
028:         *             return convertHexEncoded(str, 1);
029:         *         }
030:         *         if (oid.equals(EmailAddress))
031:         *         {
032:         *             return new DERIA5String(str);
033:         *         }
034:         *         else if (canBePrintable(str))
035:         *         {
036:         *             return new DERPrintableString(str);
037:         *         }
038:         *         else if (canBeUTF8(str))
039:         *         {
040:         *             return new DERUTF8String(str);
041:         *         }
042:         *         else
043:         *         {
044:         *             return new DERBMPString(str);
045:         *         }
046:         *     }
047:         * }
048:         */
049:        public abstract class X509NameEntryConverter {
050:            /**
051:             * Convert an inline encoded hex string rendition of an ASN.1
052:             * object back into its corresponding ASN.1 object.
053:             * 
054:             * @param str the hex encoded object
055:             * @param off the index at which the encoding starts
056:             * @return the decoded object
057:             */
058:            protected DERObject convertHexEncoded(String str, int off)
059:                    throws IOException {
060:                str = Strings.toLowerCase(str);
061:                byte[] data = new byte[(str.length() - off) / 2];
062:                for (int index = 0; index != data.length; index++) {
063:                    char left = str.charAt((index * 2) + off);
064:                    char right = str.charAt((index * 2) + off + 1);
065:
066:                    if (left < 'a') {
067:                        data[index] = (byte) ((left - '0') << 4);
068:                    } else {
069:                        data[index] = (byte) ((left - 'a' + 10) << 4);
070:                    }
071:                    if (right < 'a') {
072:                        data[index] |= (byte) (right - '0');
073:                    } else {
074:                        data[index] |= (byte) (right - 'a' + 10);
075:                    }
076:                }
077:
078:                ASN1InputStream aIn = new ASN1InputStream(data);
079:
080:                return aIn.readObject();
081:            }
082:
083:            /**
084:             * return true if the passed in String can be represented without
085:             * loss as a PrintableString, false otherwise.
086:             */
087:            protected boolean canBePrintable(String str) {
088:                return DERPrintableString.isPrintableString(str);
089:            }
090:
091:            /**
092:             * Convert the passed in String value into the appropriate ASN.1
093:             * encoded object.
094:             * 
095:             * @param oid the oid associated with the value in the DN.
096:             * @param value the value of the particular DN component.
097:             * @return the ASN.1 equivalent for the value.
098:             */
099:            public abstract DERObject getConvertedValue(
100:                    DERObjectIdentifier oid, String value);
101:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.