Example usage for java.security.cert X509Extension getExtensionValue

List of usage examples for java.security.cert X509Extension getExtensionValue

Introduction

In this page you can find the example usage for java.security.cert X509Extension getExtensionValue.

Prototype

public byte[] getExtensionValue(String oid);

Source Link

Document

Gets the DER-encoded OCTET string for the extension value (extnValue) identified by the passed-in oid String.

Usage

From source file:net.ripe.rpki.commons.crypto.x509cert.X509CertificateUtil.java

public static byte[] getSubjectKeyIdentifier(X509Extension certificate) {
    try {//from  w  w w.j a  v a  2s.c  om
        byte[] extensionValue = certificate
                .getExtensionValue(org.bouncycastle.asn1.x509.X509Extension.subjectKeyIdentifier.getId());
        if (extensionValue == null) {
            return null;
        }
        return SubjectKeyIdentifier.getInstance(X509ExtensionUtil.fromExtensionValue(extensionValue))
                .getKeyIdentifier();
    } catch (IOException e) {
        throw new X509CertificateOperationException("Cannot get SubjectKeyIdentifier for certificate", e);
    }
}

From source file:net.ripe.rpki.commons.crypto.x509cert.X509CertificateUtil.java

public static byte[] getAuthorityKeyIdentifier(X509Extension certificate) {
    try {/*from  w  w w . ja  v a 2  s . c  o  m*/
        byte[] extensionValue = certificate
                .getExtensionValue(org.bouncycastle.asn1.x509.X509Extension.authorityKeyIdentifier.getId());
        if (extensionValue == null) {
            return null;
        }
        return AuthorityKeyIdentifier.getInstance(X509ExtensionUtil.fromExtensionValue(extensionValue))
                .getKeyIdentifier();
    } catch (IOException e) {
        throw new X509CertificateOperationException("Can not get AuthorityKeyIdentifier for certificate", e);
    }
}

From source file:net.sf.keystore_explorer.crypto.x509.X509CertificateGenerator.java

private ASN1Encodable getExtensionValue(X509Extension extensions, String oid) throws CryptoException {
    ASN1InputStream ais = null;/*from  w  ww  .  j a v  a2 s. c  o m*/

    try {
        ais = new ASN1InputStream(extensions.getExtensionValue(oid));
        return ais.readObject();
    } catch (IOException ex) {
        throw new CryptoException(res.getString("CertificateGenFailed.exception.message"), ex);
    } finally {
        IOUtils.closeQuietly(ais);
    }
}