1 package org.bouncycastle.asn1.x509;
4 import java.util.Enumeration;
5 import java.math.BigInteger;
7 import org.bouncycastle.asn1.*;
8 import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
11 * The object that contains the public key stored in a certficate.
13 * The getEncoded() method in the public keys in the JCE produces a DER
14 * encoded one of these.
16 public class SubjectPublicKeyInfo
17 implements DEREncodable
19 private AlgorithmIdentifier algId;
20 private DERObject pubKey;
22 public SubjectPublicKeyInfo(
23 AlgorithmIdentifier algId,
26 this.pubKey = publicKey;
30 public SubjectPublicKeyInfo(
31 DERConstructedSequence seq)
33 Enumeration e = seq.getObjects();
35 algId = new AlgorithmIdentifier((DERConstructedSequence)e.nextElement());
37 byte[] keyData = ((DERBitString)e.nextElement()).getBytes();
41 ByteArrayInputStream bIn = new ByteArrayInputStream(keyData);
42 DERInputStream dIn = new DERInputStream(bIn);
44 pubKey = (DERObject)dIn.readObject();
46 catch (IOException ex)
48 throw new IllegalArgumentException("error recovering public key");
52 public AlgorithmIdentifier getAlgorithmId()
57 public DERObject getPublicKey()
64 * SubjectPublicKeyInfo ::= SEQUENCE {
65 * algorithm AlgorithmIdentifier,
66 * publicKey BIT STRING }
69 public DERObject getDERObject()
71 DERConstructedSequence seq = new DERConstructedSequence();
74 seq.addObject(new DERBitString(pubKey));