Source Code Cross Referenced for JCERSAPrivateCrtKey.java in  » EJB-Server-geronimo » crypto » org » apache » geronimo » crypto » jce » provider » 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.jce.provider 
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.jce.provider;
017:
018:        import java.io.ByteArrayOutputStream;
019:        import java.io.IOException;
020:        import java.math.BigInteger;
021:        import java.security.interfaces.RSAPrivateCrtKey;
022:        import java.security.spec.RSAPrivateCrtKeySpec;
023:
024:        import org.apache.geronimo.crypto.asn1.ASN1Sequence;
025:        import org.apache.geronimo.crypto.asn1.DERNull;
026:        import org.apache.geronimo.crypto.asn1.DEROutputStream;
027:        import org.apache.geronimo.crypto.asn1.pkcs.PKCSObjectIdentifiers;
028:        import org.apache.geronimo.crypto.asn1.pkcs.PrivateKeyInfo;
029:        import org.apache.geronimo.crypto.asn1.pkcs.RSAPrivateKeyStructure;
030:        import org.apache.geronimo.crypto.asn1.x509.AlgorithmIdentifier;
031:        import org.apache.geronimo.crypto.crypto.params.RSAPrivateCrtKeyParameters;
032:
033:        /**
034:         * A provider representation for a RSA private key, with CRT factors included.
035:         */
036:        public class JCERSAPrivateCrtKey extends JCERSAPrivateKey implements 
037:                RSAPrivateCrtKey {
038:            private BigInteger publicExponent;
039:            private BigInteger primeP;
040:            private BigInteger primeQ;
041:            private BigInteger primeExponentP;
042:            private BigInteger primeExponentQ;
043:            private BigInteger crtCoefficient;
044:
045:            /**
046:             * construct a private key from it's org.apache.geronimo.crypto.crypto equivalent.
047:             *
048:             * @param key the parameters object representing the private key.
049:             */
050:            JCERSAPrivateCrtKey(RSAPrivateCrtKeyParameters key) {
051:                super (key);
052:
053:                this .publicExponent = key.getPublicExponent();
054:                this .primeP = key.getP();
055:                this .primeQ = key.getQ();
056:                this .primeExponentP = key.getDP();
057:                this .primeExponentQ = key.getDQ();
058:                this .crtCoefficient = key.getQInv();
059:            }
060:
061:            /**
062:             * construct a private key from an RSAPrivateCrtKeySpec
063:             *
064:             * @param spec the spec to be used in construction.
065:             */
066:            JCERSAPrivateCrtKey(RSAPrivateCrtKeySpec spec) {
067:                this .modulus = spec.getModulus();
068:                this .publicExponent = spec.getPublicExponent();
069:                this .privateExponent = spec.getPrivateExponent();
070:                this .primeP = spec.getPrimeP();
071:                this .primeQ = spec.getPrimeQ();
072:                this .primeExponentP = spec.getPrimeExponentP();
073:                this .primeExponentQ = spec.getPrimeExponentQ();
074:                this .crtCoefficient = spec.getCrtCoefficient();
075:            }
076:
077:            /**
078:             * construct a private key from another RSAPrivateCrtKey.
079:             *
080:             * @param key the object implementing the RSAPrivateCrtKey interface.
081:             */
082:            JCERSAPrivateCrtKey(RSAPrivateCrtKey key) {
083:                this .modulus = key.getModulus();
084:                this .publicExponent = key.getPublicExponent();
085:                this .privateExponent = key.getPrivateExponent();
086:                this .primeP = key.getPrimeP();
087:                this .primeQ = key.getPrimeQ();
088:                this .primeExponentP = key.getPrimeExponentP();
089:                this .primeExponentQ = key.getPrimeExponentQ();
090:                this .crtCoefficient = key.getCrtCoefficient();
091:            }
092:
093:            /**
094:             * construct an RSA key from a private key info object.
095:             */
096:            JCERSAPrivateCrtKey(PrivateKeyInfo info) {
097:                this (new RSAPrivateKeyStructure((ASN1Sequence) info
098:                        .getPrivateKey()));
099:            }
100:
101:            /**
102:             * construct an RSA key from a ASN.1 RSA private key object.
103:             */
104:            JCERSAPrivateCrtKey(RSAPrivateKeyStructure key) {
105:                this .modulus = key.getModulus();
106:                this .publicExponent = key.getPublicExponent();
107:                this .privateExponent = key.getPrivateExponent();
108:                this .primeP = key.getPrime1();
109:                this .primeQ = key.getPrime2();
110:                this .primeExponentP = key.getExponent1();
111:                this .primeExponentQ = key.getExponent2();
112:                this .crtCoefficient = key.getCoefficient();
113:            }
114:
115:            /**
116:             * return the encoding format we produce in getEncoded().
117:             *
118:             * @return the encoding format we produce in getEncoded().
119:             */
120:            public String getFormat() {
121:                return "PKCS#8";
122:            }
123:
124:            /**
125:             * Return a PKCS8 representation of the key. The sequence returned
126:             * represents a full PrivateKeyInfo object.
127:             *
128:             * @return a PKCS8 representation of the key.
129:             */
130:            public byte[] getEncoded() {
131:                ByteArrayOutputStream bOut = new ByteArrayOutputStream();
132:                DEROutputStream dOut = new DEROutputStream(bOut);
133:                PrivateKeyInfo info = new PrivateKeyInfo(
134:                        new AlgorithmIdentifier(
135:                                PKCSObjectIdentifiers.rsaEncryption,
136:                                new DERNull()), new RSAPrivateKeyStructure(
137:                                getModulus(), getPublicExponent(),
138:                                getPrivateExponent(), getPrimeP(), getPrimeQ(),
139:                                getPrimeExponentP(), getPrimeExponentQ(),
140:                                getCrtCoefficient()).getDERObject());
141:
142:                try {
143:                    dOut.writeObject(info);
144:                    dOut.close();
145:                } catch (IOException e) {
146:                    throw new RuntimeException("Error encoding RSA public key",
147:                            e);
148:                }
149:
150:                return bOut.toByteArray();
151:            }
152:
153:            /**
154:             * return the public exponent.
155:             *
156:             * @return the public exponent.
157:             */
158:            public BigInteger getPublicExponent() {
159:                return publicExponent;
160:            }
161:
162:            /**
163:             * return the prime P.
164:             *
165:             * @return the prime P.
166:             */
167:            public BigInteger getPrimeP() {
168:                return primeP;
169:            }
170:
171:            /**
172:             * return the prime Q.
173:             *
174:             * @return the prime Q.
175:             */
176:            public BigInteger getPrimeQ() {
177:                return primeQ;
178:            }
179:
180:            /**
181:             * return the prime exponent for P.
182:             *
183:             * @return the prime exponent for P.
184:             */
185:            public BigInteger getPrimeExponentP() {
186:                return primeExponentP;
187:            }
188:
189:            /**
190:             * return the prime exponent for Q.
191:             *
192:             * @return the prime exponent for Q.
193:             */
194:            public BigInteger getPrimeExponentQ() {
195:                return primeExponentQ;
196:            }
197:
198:            /**
199:             * return the CRT coefficient.
200:             *
201:             * @return the CRT coefficient.
202:             */
203:            public BigInteger getCrtCoefficient() {
204:                return crtCoefficient;
205:            }
206:
207:            public boolean equals(Object o) {
208:                if (!(o instanceof  RSAPrivateCrtKey)) {
209:                    return false;
210:                }
211:
212:                if (o == this ) {
213:                    return true;
214:                }
215:
216:                RSAPrivateCrtKey key = (RSAPrivateCrtKey) o;
217:
218:                return this .getModulus().equals(key.getModulus())
219:                        && this .getPublicExponent().equals(
220:                                key.getPublicExponent())
221:                        && this .getPrivateExponent().equals(
222:                                key.getPrivateExponent())
223:                        && this .getPrimeP().equals(key.getPrimeP())
224:                        && this .getPrimeQ().equals(key.getPrimeQ())
225:                        && this .getPrimeExponentP().equals(
226:                                key.getPrimeExponentP())
227:                        && this .getPrimeExponentQ().equals(
228:                                key.getPrimeExponentQ())
229:                        && this .getCrtCoefficient().equals(
230:                                key.getCrtCoefficient());
231:            }
232:
233:            public String toString() {
234:                StringBuffer buf = new StringBuffer();
235:                String nl = System.getProperty("line.separator");
236:
237:                buf.append("RSA Private CRT Key" + nl);
238:                buf.append("            modulus: "
239:                        + this .getModulus().toString(16) + nl);
240:                buf.append("    public exponent: "
241:                        + this .getPublicExponent().toString(16) + nl);
242:                buf.append("   private exponent: "
243:                        + this .getPrivateExponent().toString(16) + nl);
244:                buf.append("             primeP: "
245:                        + this .getPrimeP().toString(16) + nl);
246:                buf.append("             primeQ: "
247:                        + this .getPrimeQ().toString(16) + nl);
248:                buf.append("     primeExponentP: "
249:                        + this .getPrimeExponentP().toString(16) + nl);
250:                buf.append("     primeExponentQ: "
251:                        + this .getPrimeExponentQ().toString(16) + nl);
252:                buf.append("     crtCoefficient: "
253:                        + this .getCrtCoefficient().toString(16) + nl);
254:
255:                return buf.toString();
256:            }
257:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.