Exemplo n.º 1
0
  private String generateSubjectKeyIdentifier(Certificate certificate) throws IOException {
    String subjectKeyIdentifier;
    ASN1InputStream is;
    SubjectPublicKeyInfo spki;
    SubjectKeyIdentifier ski;

    subjectKeyIdentifier = null;
    is = null;
    spki = null;
    ski = null;

    try {
      is = new ASN1InputStream(certificate.getPublicKey().getEncoded());

      spki = new SubjectPublicKeyInfo((ASN1Sequence) is.readObject());
      ski = new SubjectKeyIdentifier(spki);
    } finally {
      if (is != null) {
        is.close();
      }
    }

    subjectKeyIdentifier = new String(Hex.encode(ski.getKeyIdentifier()));

    return subjectKeyIdentifier;
  }
 private byte[] getSubjectKeyId(X509Certificate cert) throws IOException {
   byte[] extvalue = cert.getExtensionValue(X509Extensions.SubjectKeyIdentifier.getId());
   if (extvalue == null) {
     return null;
   }
   ASN1OctetString str =
       ASN1OctetString.getInstance(
           new ASN1InputStream(new ByteArrayInputStream(extvalue)).readObject());
   SubjectKeyIdentifier keyId =
       SubjectKeyIdentifier.getInstance(
           new ASN1InputStream(new ByteArrayInputStream(str.getOctets())).readObject());
   return keyId.getKeyIdentifier();
 }
Exemplo n.º 3
0
 /**
  * Reads the value of the <code>SubjectKeyIdentifier</code> extension field of the certificate.
  *
  * @return Subject key identifier.
  */
 public SubjectKeyIdentifier readSubjectKeyIdentifier() {
   return SubjectKeyIdentifier.getInstance(read(ExtensionType.SubjectKeyIdentifier));
 }