1 17 18 package org.apache.geronimo.util.asn1.x509; 19 20 import java.io.ByteArrayInputStream ; 21 import java.io.IOException ; 22 import java.util.Enumeration ; 23 24 import org.apache.geronimo.util.asn1.ASN1Encodable; 25 import org.apache.geronimo.util.asn1.ASN1EncodableVector; 26 import org.apache.geronimo.util.asn1.ASN1InputStream; 27 import org.apache.geronimo.util.asn1.ASN1Sequence; 28 import org.apache.geronimo.util.asn1.ASN1TaggedObject; 29 import org.apache.geronimo.util.asn1.DERBitString; 30 import org.apache.geronimo.util.asn1.DEREncodable; 31 import org.apache.geronimo.util.asn1.DERObject; 32 import org.apache.geronimo.util.asn1.DERSequence; 33 34 40 public class SubjectPublicKeyInfo 41 extends ASN1Encodable 42 { 43 private AlgorithmIdentifier algId; 44 private DERBitString keyData; 45 46 public static SubjectPublicKeyInfo getInstance( 47 ASN1TaggedObject obj, 48 boolean explicit) 49 { 50 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 51 } 52 53 public static SubjectPublicKeyInfo getInstance( 54 Object obj) 55 { 56 if (obj instanceof SubjectPublicKeyInfo) 57 { 58 return (SubjectPublicKeyInfo)obj; 59 } 60 else if (obj instanceof ASN1Sequence) 61 { 62 return new SubjectPublicKeyInfo((ASN1Sequence)obj); 63 } 64 65 throw new IllegalArgumentException ("unknown object in factory"); 66 } 67 68 public SubjectPublicKeyInfo( 69 AlgorithmIdentifier algId, 70 DEREncodable publicKey) 71 { 72 this.keyData = new DERBitString(publicKey); 73 this.algId = algId; 74 } 75 76 public SubjectPublicKeyInfo( 77 AlgorithmIdentifier algId, 78 byte[] publicKey) 79 { 80 this.keyData = new DERBitString(publicKey); 81 this.algId = algId; 82 } 83 84 public SubjectPublicKeyInfo( 85 ASN1Sequence seq) 86 { 87 Enumeration e = seq.getObjects(); 88 89 this.algId = AlgorithmIdentifier.getInstance(e.nextElement()); 90 this.keyData = (DERBitString)e.nextElement(); 91 } 92 93 public AlgorithmIdentifier getAlgorithmId() 94 { 95 return algId; 96 } 97 98 105 public DERObject getPublicKey() 106 throws IOException 107 { 108 ByteArrayInputStream bIn = new ByteArrayInputStream (keyData.getBytes()); 109 ASN1InputStream aIn = new ASN1InputStream(bIn); 110 111 return aIn.readObject(); 112 } 113 114 117 public DERBitString getPublicKeyData() 118 { 119 return keyData; 120 } 121 122 130 public DERObject toASN1Object() 131 { 132 ASN1EncodableVector v = new ASN1EncodableVector(); 133 134 v.add(algId); 135 v.add(keyData); 136 137 return new DERSequence(v); 138 } 139 } 140 | Popular Tags |