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


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