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


001:        package org.bouncycastle.asn1.pkcs;
002:
003:        import java.math.BigInteger;
004:        import java.util.Enumeration;
005:
006:        import org.bouncycastle.asn1.ASN1Encodable;
007:        import org.bouncycastle.asn1.ASN1EncodableVector;
008:        import org.bouncycastle.asn1.ASN1Sequence;
009:        import org.bouncycastle.asn1.ASN1TaggedObject;
010:        import org.bouncycastle.asn1.DERInteger;
011:        import org.bouncycastle.asn1.DERObject;
012:        import org.bouncycastle.asn1.DERSequence;
013:
014:        public class RSAPrivateKeyStructure extends ASN1Encodable {
015:            private int version;
016:            private BigInteger modulus;
017:            private BigInteger publicExponent;
018:            private BigInteger privateExponent;
019:            private BigInteger prime1;
020:            private BigInteger prime2;
021:            private BigInteger exponent1;
022:            private BigInteger exponent2;
023:            private BigInteger coefficient;
024:            private ASN1Sequence otherPrimeInfos = null;
025:
026:            public static RSAPrivateKeyStructure getInstance(
027:                    ASN1TaggedObject obj, boolean explicit) {
028:                return getInstance(ASN1Sequence.getInstance(obj, explicit));
029:            }
030:
031:            public static RSAPrivateKeyStructure getInstance(Object obj) {
032:                if (obj instanceof  RSAPrivateKeyStructure) {
033:                    return (RSAPrivateKeyStructure) obj;
034:                } else if (obj instanceof  ASN1Sequence) {
035:                    return new RSAPrivateKeyStructure((ASN1Sequence) obj);
036:                }
037:
038:                throw new IllegalArgumentException("unknown object in factory");
039:            }
040:
041:            public RSAPrivateKeyStructure(BigInteger modulus,
042:                    BigInteger publicExponent, BigInteger privateExponent,
043:                    BigInteger prime1, BigInteger prime2, BigInteger exponent1,
044:                    BigInteger exponent2, BigInteger coefficient) {
045:                this .version = 0;
046:                this .modulus = modulus;
047:                this .publicExponent = publicExponent;
048:                this .privateExponent = privateExponent;
049:                this .prime1 = prime1;
050:                this .prime2 = prime2;
051:                this .exponent1 = exponent1;
052:                this .exponent2 = exponent2;
053:                this .coefficient = coefficient;
054:            }
055:
056:            public RSAPrivateKeyStructure(ASN1Sequence seq) {
057:                Enumeration e = seq.getObjects();
058:
059:                BigInteger v = ((DERInteger) e.nextElement()).getValue();
060:                if (v.intValue() != 0 && v.intValue() != 1) {
061:                    throw new IllegalArgumentException(
062:                            "wrong version for RSA private key");
063:                }
064:
065:                version = v.intValue();
066:                modulus = ((DERInteger) e.nextElement()).getValue();
067:                publicExponent = ((DERInteger) e.nextElement()).getValue();
068:                privateExponent = ((DERInteger) e.nextElement()).getValue();
069:                prime1 = ((DERInteger) e.nextElement()).getValue();
070:                prime2 = ((DERInteger) e.nextElement()).getValue();
071:                exponent1 = ((DERInteger) e.nextElement()).getValue();
072:                exponent2 = ((DERInteger) e.nextElement()).getValue();
073:                coefficient = ((DERInteger) e.nextElement()).getValue();
074:
075:                if (e.hasMoreElements()) {
076:                    otherPrimeInfos = (ASN1Sequence) e.nextElement();
077:                }
078:            }
079:
080:            public int getVersion() {
081:                return version;
082:            }
083:
084:            public BigInteger getModulus() {
085:                return modulus;
086:            }
087:
088:            public BigInteger getPublicExponent() {
089:                return publicExponent;
090:            }
091:
092:            public BigInteger getPrivateExponent() {
093:                return privateExponent;
094:            }
095:
096:            public BigInteger getPrime1() {
097:                return prime1;
098:            }
099:
100:            public BigInteger getPrime2() {
101:                return prime2;
102:            }
103:
104:            public BigInteger getExponent1() {
105:                return exponent1;
106:            }
107:
108:            public BigInteger getExponent2() {
109:                return exponent2;
110:            }
111:
112:            public BigInteger getCoefficient() {
113:                return coefficient;
114:            }
115:
116:            /**
117:             * This outputs the key in PKCS1v2 format.
118:             * <pre>
119:             *      RSAPrivateKey ::= SEQUENCE {
120:             *                          version Version,
121:             *                          modulus INTEGER, -- n
122:             *                          publicExponent INTEGER, -- e
123:             *                          privateExponent INTEGER, -- d
124:             *                          prime1 INTEGER, -- p
125:             *                          prime2 INTEGER, -- q
126:             *                          exponent1 INTEGER, -- d mod (p-1)
127:             *                          exponent2 INTEGER, -- d mod (q-1)
128:             *                          coefficient INTEGER, -- (inverse of q) mod p
129:             *                          otherPrimeInfos OtherPrimeInfos OPTIONAL
130:             *                      }
131:             *
132:             *      Version ::= INTEGER { two-prime(0), multi(1) }
133:             *        (CONSTRAINED BY {-- version must be multi if otherPrimeInfos present --})
134:             * </pre>
135:             * <p>
136:             * This routine is written to output PKCS1 version 2.1, private keys.
137:             */
138:            public DERObject toASN1Object() {
139:                ASN1EncodableVector v = new ASN1EncodableVector();
140:
141:                v.add(new DERInteger(version)); // version
142:                v.add(new DERInteger(getModulus()));
143:                v.add(new DERInteger(getPublicExponent()));
144:                v.add(new DERInteger(getPrivateExponent()));
145:                v.add(new DERInteger(getPrime1()));
146:                v.add(new DERInteger(getPrime2()));
147:                v.add(new DERInteger(getExponent1()));
148:                v.add(new DERInteger(getExponent2()));
149:                v.add(new DERInteger(getCoefficient()));
150:
151:                if (otherPrimeInfos != null) {
152:                    v.add(otherPrimeInfos);
153:                }
154:
155:                return new DERSequence(v);
156:            }
157:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.