Source Code Cross Referenced for RSAPrivateKeyStructure.java in  » EJB-Server-geronimo » crypto » org » apache » geronimo » crypto » asn1 » pkcs » 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 » EJB Server geronimo » crypto » org.apache.geronimo.crypto.asn1.pkcs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.crypto.asn1.pkcs;
017:
018:        import java.math.BigInteger;
019:        import java.util.Enumeration;
020:
021:        import org.apache.geronimo.crypto.asn1.ASN1Encodable;
022:        import org.apache.geronimo.crypto.asn1.ASN1EncodableVector;
023:        import org.apache.geronimo.crypto.asn1.ASN1Sequence;
024:        import org.apache.geronimo.crypto.asn1.ASN1TaggedObject;
025:        import org.apache.geronimo.crypto.asn1.DERInteger;
026:        import org.apache.geronimo.crypto.asn1.DERObject;
027:        import org.apache.geronimo.crypto.asn1.DERSequence;
028:
029:        public class RSAPrivateKeyStructure extends ASN1Encodable {
030:            private int version;
031:            private BigInteger modulus;
032:            private BigInteger publicExponent;
033:            private BigInteger privateExponent;
034:            private BigInteger prime1;
035:            private BigInteger prime2;
036:            private BigInteger exponent1;
037:            private BigInteger exponent2;
038:            private BigInteger coefficient;
039:            private ASN1Sequence otherPrimeInfos = null;
040:
041:            public static RSAPrivateKeyStructure getInstance(
042:                    ASN1TaggedObject obj, boolean explicit) {
043:                return getInstance(ASN1Sequence.getInstance(obj, explicit));
044:            }
045:
046:            public static RSAPrivateKeyStructure getInstance(Object obj) {
047:                if (obj instanceof  RSAPrivateKeyStructure) {
048:                    return (RSAPrivateKeyStructure) obj;
049:                } else if (obj instanceof  ASN1Sequence) {
050:                    return new RSAPrivateKeyStructure((ASN1Sequence) obj);
051:                }
052:
053:                throw new IllegalArgumentException("unknown object in factory");
054:            }
055:
056:            public RSAPrivateKeyStructure(BigInteger modulus,
057:                    BigInteger publicExponent, BigInteger privateExponent,
058:                    BigInteger prime1, BigInteger prime2, BigInteger exponent1,
059:                    BigInteger exponent2, BigInteger coefficient) {
060:                this .version = 0;
061:                this .modulus = modulus;
062:                this .publicExponent = publicExponent;
063:                this .privateExponent = privateExponent;
064:                this .prime1 = prime1;
065:                this .prime2 = prime2;
066:                this .exponent1 = exponent1;
067:                this .exponent2 = exponent2;
068:                this .coefficient = coefficient;
069:            }
070:
071:            public RSAPrivateKeyStructure(ASN1Sequence seq) {
072:                Enumeration e = seq.getObjects();
073:
074:                BigInteger v = ((DERInteger) e.nextElement()).getValue();
075:                if (v.intValue() != 0 && v.intValue() != 1) {
076:                    throw new IllegalArgumentException(
077:                            "wrong version for RSA private key");
078:                }
079:
080:                version = v.intValue();
081:                modulus = ((DERInteger) e.nextElement()).getValue();
082:                publicExponent = ((DERInteger) e.nextElement()).getValue();
083:                privateExponent = ((DERInteger) e.nextElement()).getValue();
084:                prime1 = ((DERInteger) e.nextElement()).getValue();
085:                prime2 = ((DERInteger) e.nextElement()).getValue();
086:                exponent1 = ((DERInteger) e.nextElement()).getValue();
087:                exponent2 = ((DERInteger) e.nextElement()).getValue();
088:                coefficient = ((DERInteger) e.nextElement()).getValue();
089:
090:                if (e.hasMoreElements()) {
091:                    otherPrimeInfos = (ASN1Sequence) e.nextElement();
092:                }
093:            }
094:
095:            public int getVersion() {
096:                return version;
097:            }
098:
099:            public BigInteger getModulus() {
100:                return modulus;
101:            }
102:
103:            public BigInteger getPublicExponent() {
104:                return publicExponent;
105:            }
106:
107:            public BigInteger getPrivateExponent() {
108:                return privateExponent;
109:            }
110:
111:            public BigInteger getPrime1() {
112:                return prime1;
113:            }
114:
115:            public BigInteger getPrime2() {
116:                return prime2;
117:            }
118:
119:            public BigInteger getExponent1() {
120:                return exponent1;
121:            }
122:
123:            public BigInteger getExponent2() {
124:                return exponent2;
125:            }
126:
127:            public BigInteger getCoefficient() {
128:                return coefficient;
129:            }
130:
131:            /**
132:             * This outputs the key in PKCS1v2 format.
133:             * <pre>
134:             *      RSAPrivateKey ::= SEQUENCE {
135:             *                          version Version,
136:             *                          modulus INTEGER, -- n
137:             *                          publicExponent INTEGER, -- e
138:             *                          privateExponent INTEGER, -- d
139:             *                          prime1 INTEGER, -- p
140:             *                          prime2 INTEGER, -- q
141:             *                          exponent1 INTEGER, -- d mod (p-1)
142:             *                          exponent2 INTEGER, -- d mod (q-1)
143:             *                          coefficient INTEGER, -- (inverse of q) mod p
144:             *                          otherPrimeInfos OtherPrimeInfos OPTIONAL
145:             *                      }
146:             *
147:             *      Version ::= INTEGER { two-prime(0), multi(1) }
148:             *        (CONSTRAINED BY {-- version must be multi if otherPrimeInfos present --})
149:             * </pre>
150:             * <p>
151:             * This routine is written to output PKCS1 version 2.1, private keys.
152:             */
153:            public DERObject toASN1Object() {
154:                ASN1EncodableVector v = new ASN1EncodableVector();
155:
156:                v.add(new DERInteger(version)); // version
157:                v.add(new DERInteger(getModulus()));
158:                v.add(new DERInteger(getPublicExponent()));
159:                v.add(new DERInteger(getPrivateExponent()));
160:                v.add(new DERInteger(getPrime1()));
161:                v.add(new DERInteger(getPrime2()));
162:                v.add(new DERInteger(getExponent1()));
163:                v.add(new DERInteger(getExponent2()));
164:                v.add(new DERInteger(getCoefficient()));
165:
166:                if (otherPrimeInfos != null) {
167:                    v.add(otherPrimeInfos);
168:                }
169:
170:                return new DERSequence(v);
171:            }
172:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.