2002/03/21 01:19:32
[org.ibex.core.git] / src / org / bouncycastle / asn1 / x509 / RSAPublicKeyStructure.java
1 package org.bouncycastle.asn1.x509;
2
3 import java.util.Enumeration;
4 import java.math.BigInteger;
5
6 import org.bouncycastle.asn1.*;
7
8 public class RSAPublicKeyStructure
9     implements DEREncodable
10 {
11     private BigInteger  modulus;
12     private BigInteger  publicExponent;
13
14     public RSAPublicKeyStructure(
15         BigInteger  modulus,
16         BigInteger  publicExponent)
17     {
18         this.modulus = modulus;
19         this.publicExponent = publicExponent;
20     }
21
22     public RSAPublicKeyStructure(
23         DERConstructedSequence  seq)
24     {
25         Enumeration e = seq.getObjects();
26
27         modulus = ((DERInteger)e.nextElement()).getValue();
28         publicExponent = ((DERInteger)e.nextElement()).getValue();
29     }
30
31     public BigInteger getModulus()
32     {
33         return modulus;
34     }
35
36     public BigInteger getPublicExponent()
37     {
38         return publicExponent;
39     }
40
41     /**
42      * This outputs the key in PKCS1v2 format.
43      * <pre>
44      *      RSAPublicKey ::= SEQUENCE {
45      *                          modulus INTEGER, -- n
46      *                          publicExponent INTEGER, -- e
47      *                      }
48      * </pre>
49      * <p>
50      */
51     public DERObject getDERObject()
52     {
53         DERConstructedSequence  seq = new DERConstructedSequence();
54
55         seq.addObject(new DERInteger(getModulus()));
56         seq.addObject(new DERInteger(getPublicExponent()));
57
58         return seq;
59     }
60 }