1 17 18 package org.apache.geronimo.util.asn1.x509; 19 20 import java.math.BigInteger ; 21 import java.util.Enumeration ; 22 23 import org.apache.geronimo.util.asn1.ASN1Encodable; 24 import org.apache.geronimo.util.asn1.ASN1EncodableVector; 25 import org.apache.geronimo.util.asn1.ASN1Sequence; 26 import org.apache.geronimo.util.asn1.ASN1TaggedObject; 27 import org.apache.geronimo.util.asn1.DERInteger; 28 import org.apache.geronimo.util.asn1.DERObject; 29 import org.apache.geronimo.util.asn1.DERSequence; 30 31 public class RSAPublicKeyStructure 32 extends ASN1Encodable 33 { 34 private BigInteger modulus; 35 private BigInteger publicExponent; 36 37 public static RSAPublicKeyStructure getInstance( 38 ASN1TaggedObject obj, 39 boolean explicit) 40 { 41 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 42 } 43 44 public static RSAPublicKeyStructure getInstance( 45 Object obj) 46 { 47 if(obj == null || obj instanceof RSAPublicKeyStructure) 48 { 49 return (RSAPublicKeyStructure)obj; 50 } 51 52 if(obj instanceof ASN1Sequence) 53 { 54 return new RSAPublicKeyStructure((ASN1Sequence)obj); 55 } 56 57 throw new IllegalArgumentException ("Invalid RSAPublicKeyStructure: " + obj.getClass().getName()); 58 } 59 60 public RSAPublicKeyStructure( 61 BigInteger modulus, 62 BigInteger publicExponent) 63 { 64 this.modulus = modulus; 65 this.publicExponent = publicExponent; 66 } 67 68 public RSAPublicKeyStructure( 69 ASN1Sequence seq) 70 { 71 Enumeration e = seq.getObjects(); 72 73 modulus = ((DERInteger)e.nextElement()).getPositiveValue(); 74 publicExponent = ((DERInteger)e.nextElement()).getPositiveValue(); 75 } 76 77 public BigInteger getModulus() 78 { 79 return modulus; 80 } 81 82 public BigInteger getPublicExponent() 83 { 84 return publicExponent; 85 } 86 87 97 public DERObject toASN1Object() 98 { 99 ASN1EncodableVector v = new ASN1EncodableVector(); 100 101 v.add(new DERInteger(getModulus())); 102 v.add(new DERInteger(getPublicExponent())); 103 104 return new DERSequence(v); 105 } 106 } 107 | Popular Tags |