01: package org.bouncycastle.x509.extension;
02:
03: import java.io.IOException;
04: import java.security.PublicKey;
05: import java.security.cert.CertificateParsingException;
06:
07: import org.bouncycastle.asn1.ASN1InputStream;
08: import org.bouncycastle.asn1.ASN1OctetString;
09: import org.bouncycastle.asn1.ASN1Sequence;
10: import org.bouncycastle.asn1.x509.AuthorityKeyIdentifier;
11: import org.bouncycastle.asn1.x509.SubjectKeyIdentifier;
12: import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
13:
14: /**
15: * A high level subject key identifier.
16: */
17: public class SubjectKeyIdentifierStructure extends SubjectKeyIdentifier {
18: private AuthorityKeyIdentifier authKeyID;
19:
20: /**
21: * Constructor which will take the byte[] returned from getExtensionValue()
22: *
23: * @param encodedValue a DER octet encoded string with the extension structure in it.
24: * @throws IOException on parsing errors.
25: */
26: public SubjectKeyIdentifierStructure(byte[] encodedValue)
27: throws IOException {
28: super ((ASN1OctetString) X509ExtensionUtil
29: .fromExtensionValue(encodedValue));
30: }
31:
32: private static ASN1OctetString fromPublicKey(PublicKey pubKey)
33: throws CertificateParsingException {
34: try {
35: SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(
36: (ASN1Sequence) new ASN1InputStream(pubKey
37: .getEncoded()).readObject());
38:
39: return (ASN1OctetString) (new SubjectKeyIdentifier(info)
40: .toASN1Object());
41: } catch (Exception e) {
42: throw new CertificateParsingException(
43: "Exception extracting certificate details: "
44: + e.toString());
45: }
46: }
47:
48: public SubjectKeyIdentifierStructure(PublicKey pubKey)
49: throws CertificateParsingException {
50: super(fromPublicKey(pubKey));
51: }
52: }
|