1 package org.bouncycastle.asn1.x509;
3 import java.util.Enumeration;
4 import java.math.BigInteger;
6 import org.bouncycastle.asn1.*;
8 public class RSAPublicKeyStructure
9 implements DEREncodable
11 private BigInteger modulus;
12 private BigInteger publicExponent;
14 public static RSAPublicKeyStructure getInstance(
18 return getInstance(ASN1Sequence.getInstance(obj, explicit));
21 public static RSAPublicKeyStructure getInstance(
24 if(obj == null || obj instanceof RSAPublicKeyStructure)
26 return (RSAPublicKeyStructure)obj;
29 if(obj instanceof ASN1Sequence)
31 return new RSAPublicKeyStructure((ASN1Sequence)obj);
34 throw new IllegalArgumentException("Invalid RSAPublicKeyStructure: " + obj.getClass().getName());
37 public RSAPublicKeyStructure(
39 BigInteger publicExponent)
41 this.modulus = modulus;
42 this.publicExponent = publicExponent;
45 public RSAPublicKeyStructure(
48 Enumeration e = seq.getObjects();
50 modulus = ((DERInteger)e.nextElement()).getValue();
51 publicExponent = ((DERInteger)e.nextElement()).getValue();
54 public BigInteger getModulus()
59 public BigInteger getPublicExponent()
61 return publicExponent;
65 * This outputs the key in PKCS1v2 format.
67 * RSAPublicKey ::= SEQUENCE {
68 * modulus INTEGER, -- n
69 * publicExponent INTEGER, -- e
74 public DERObject getDERObject()
76 DERConstructedSequence seq = new DERConstructedSequence();
78 seq.addObject(new DERInteger(getModulus()));
79 seq.addObject(new DERInteger(getPublicExponent()));