Example usage for org.bouncycastle.asn1 DEROctetString getOctets

List of usage examples for org.bouncycastle.asn1 DEROctetString getOctets

Introduction

In this page you can find the example usage for org.bouncycastle.asn1 DEROctetString getOctets.

Prototype

public byte[] getOctets() 

Source Link

Document

Return the content of the OCTET STRING as a byte array.

Usage

From source file:de.fraunhofer.fokus.openeid.pace.PaceECDH.java

License:Open Source License

public byte[] parseGetPointResponse(byte[] response) throws IOException {
    DERApplicationSpecific dataObject = (DERApplicationSpecific) DERApplicationSpecific.fromByteArray(response);
    ASN1Sequence sequence = ASN1Sequence.getInstance(dataObject.getObject(DERTags.SEQUENCE));
    DERTaggedObject tagged = (DERTaggedObject) sequence.getObjectAt(0);
    DEROctetString octetString = (DEROctetString) tagged.getObjectParser(DERTags.OCTET_STRING, false);
    return octetString.getOctets();
}

From source file:de.fraunhofer.fokus.openeid.structure.SequenceData.java

License:Open Source License

/**
 * TaggedObject with value only (OctetString),
 * then the OctetString is retrieved/*from www .j  a va  2s  .  co m*/
 * @param tagged
 * @return byte array representation of the retrieved content
 */
public static byte[] getContent(DERTaggedObject tagged) {
    if (tagged != null) {
        DEREncodable objectParser = tagged.getObjectParser(DERTags.TAGGED, true);
        DEROctetString inner = (DEROctetString) objectParser;
        return inner.getOctets();
    } else {
        return new byte[0];
    }
}

From source file:de.mendelson.util.security.cert.KeystoreCertificate.java

public List<String> getAuthorityKeyIdentifier() {
    List<String> authorityKeyIdentifierList = new ArrayList<String>();
    byte[] extensionValue = this.certificate.getExtensionValue("2.5.29.35");
    if (extensionValue == null) {
        return (authorityKeyIdentifierList);
    }/*from  w w  w  .  j ava2 s .co m*/
    try {
        byte[] octedBytes = ((ASN1OctetString) ASN1Primitive.fromByteArray(extensionValue)).getOctets();
        ASN1Sequence asn1Sequence = (ASN1Sequence) ASN1Primitive.fromByteArray(octedBytes);
        for (int i = 0, len = asn1Sequence.size(); i < len; i++) {
            DERTaggedObject derTagObj = (DERTaggedObject) asn1Sequence.getObjectAt(i);
            if (derTagObj.getTagNo() == 0) {
                DEROctetString octetStr = (DEROctetString) derTagObj.getObject();
                byte[] identifier = octetStr.getOctets();
                authorityKeyIdentifierList.add("[Key identifier] " + byteArrayToHexStr(identifier));
            } else if (derTagObj.getTagNo() == 2) {
                DEROctetString octetStr = (DEROctetString) derTagObj.getObject();
                byte[] identifier = octetStr.getOctets();
                authorityKeyIdentifierList.add("[Serial] " + byteArrayToHexStr(identifier));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return (authorityKeyIdentifierList);
}

From source file:de.mendelson.util.security.cert.KeystoreCertificate.java

public List<String> getSubjectKeyIdentifier() {
    List<String> subjectKeyIdentifierList = new ArrayList<String>();
    byte[] extensionValue = this.certificate.getExtensionValue("2.5.29.14");
    if (extensionValue == null) {
        return (subjectKeyIdentifierList);
    }//w w w . ja  v  a2 s  .  c  om
    try {
        byte[] octedBytes = ((ASN1OctetString) ASN1Primitive.fromByteArray(extensionValue)).getOctets();
        DEROctetString octetStr = (DEROctetString) ASN1Primitive.fromByteArray(octedBytes);
        byte[] identifier = octetStr.getOctets();
        subjectKeyIdentifierList.add(byteArrayToHexStr(identifier));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return (subjectKeyIdentifierList);
}

From source file:de.thiemann.ssl.report.model.CertificateV3.java

License:Open Source License

private List<String> transferDistributionPoints(byte[] extension) {
    if (extension == null)
        return null;

    ASN1Sequence crlDistributionPoints = null;

    try {// w  w w .jav a  2 s.c om
        ASN1Object o = null;

        o = (DEROctetString) ASN1Object.fromByteArray(extension);
        if (o instanceof DEROctetString) {
            DEROctetString octStr = (DEROctetString) o;

            o = ASN1Object.fromByteArray(octStr.getOctets());
            if (o instanceof ASN1Sequence) {
                crlDistributionPoints = (ASN1Sequence) o;
            }
        }

    } catch (IOException e) {
        e.printStackTrace();
    }

    if (crlDistributionPoints == null)
        return null;

    List<String> l = new ArrayList<String>();
    Enumeration<?> e = crlDistributionPoints.getObjects();
    while (e.hasMoreElements()) {
        Object o = e.nextElement();

        if (o instanceof ASN1Sequence) {
            ASN1Sequence seqDP = (ASN1Sequence) o;
            DistributionPoint dp = new DistributionPoint(seqDP);

            DistributionPointName dpn = dp.getDistributionPoint();
            ASN1Encodable enc = dpn.getName();

            if (enc instanceof GeneralNames) {
                GeneralNames gns = (GeneralNames) enc;

                for (GeneralName gn : gns.getNames()) {
                    l.add(gn.toString());
                }
            }
        }
    }

    if (!l.isEmpty())
        return l;
    else
        return null;
}

From source file:de.tsenger.animamea.asn1.AmECPublicKey.java

License:Open Source License

/** Returns base point G
 * @return/* www.  j  a  v  a2s.c o m*/
 */
public byte[] getG() {
    if (G == null)
        return null;
    DEROctetString ostr = (DEROctetString) DEROctetString.getInstance(G, false);
    return ostr.getOctets();
}

From source file:de.tsenger.animamea.asn1.AmECPublicKey.java

License:Open Source License

/** Returns public point Y
 * @return// ww  w . j a  v  a  2s .  c  o m
 */
public byte[] getY() {
    if (Y == null)
        return null;
    DEROctetString ostr = (DEROctetString) DEROctetString.getInstance(Y, false);
    return ostr.getOctets();
}

From source file:de.tsenger.animamea.asn1.CertificateHolderAuthorizationTemplate.java

License:Open Source License

/** Constructor for Decoding CHAT from SEQUENCE
 * @param chatSeq/* ww  w .  j a va2  s .c o  m*/
 * @throws IOException
 */
public CertificateHolderAuthorizationTemplate(ASN1Sequence chatSeq) throws IOException {
    this.terminalType = (ASN1ObjectIdentifier) chatSeq.getObjectAt(0);

    DEROctetString oct = (DEROctetString) ((DERApplicationSpecific) chatSeq.getObjectAt(1))
            .getObject(BERTags.OCTET_STRING);
    this.auth = new DiscretionaryData(oct.getOctets());

}

From source file:de.tsenger.animamea.asn1.DynamicAuthenticationData.java

License:Open Source License

/**
 * Liefert den Inhalt des Tagged Objects mit dem Tag (0x80 & tagno) zurck.
 * @param tagno/*from www  . j av a2 s  . co  m*/
 * @return
 */
public byte[] getDataObject(int tagno) {
    for (DERTaggedObject item : objects) {
        if (item.getTagNo() == tagno) {
            DEROctetString ostr = (DEROctetString) item.getObjectParser(BERTags.OCTET_STRING, false);
            return ostr.getOctets();
        }
    }
    return null;
}

From source file:de.tsenger.animamea.iso7816.DO87.java

License:Open Source License

public void fromByteArray(byte[] encodedData) {
    ASN1InputStream asn1in = new ASN1InputStream(encodedData);
    try {/*from  www. jav  a  2s .c  o  m*/
        to = (DERTaggedObject) asn1in.readObject();
        asn1in.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    DEROctetString ocs = (DEROctetString) to.getObject();
    value_ = ocs.getOctets();
    data = removePaddingIndicator(value_);

}