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