Search in sources :

Example 76 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class CertificateAlgorithmId method encode.

/**
 * Encode the algorithm identifier in DER form to the stream.
 *
 * @param out the DerOutputStream to marshal the contents to.
 * @exception IOException on errors.
 */
@Override
public void encode(OutputStream out) throws IOException {
    DerOutputStream tmp = new DerOutputStream();
    algId.encode(tmp);
    out.write(tmp.toByteArray());
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Example 77 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class CertificatePoliciesExtension method encodeThis.

// Encode this extension value
private void encodeThis() throws IOException {
    try (DerOutputStream os = new DerOutputStream()) {
        DerOutputStream tmp = new DerOutputStream();
        for (int i = 0; i < mInfos.size(); i++) {
            mInfos.elementAt(i).encode(tmp);
        }
        os.write(DerValue.tag_Sequence, tmp);
        extensionValue = os.toByteArray();
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Example 78 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class AVA method derEncode.

/**
 * DER encode this object onto an output stream.
 * Implements the <code>DerEncoder</code> interface.
 *
 * @param out
 *            the output stream on which to write the DER encoding.
 *
 * @exception IOException on encoding error.
 */
@Override
public void derEncode(OutputStream out) throws IOException {
    try (DerOutputStream tmp2 = new DerOutputStream()) {
        DerOutputStream tmp = new DerOutputStream();
        tmp.putOID(oid);
        value.encode(tmp);
        tmp2.write(DerValue.tag_Sequence, tmp);
        out.write(tmp2.toByteArray());
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Example 79 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class AlgorithmId method derEncodeWithContext.

/**
 * DER encode this object onto an output stream.
 * Implements the <code>DerEncoder</code> interface.
 *
 * @param out the output stream on which to write the DER encoding params,
 *            using context value.
 * @param contextVal context value
 *
 * @exception IOException on encoding error.
 */
public void derEncodeWithContext(OutputStream out, int contextVal) throws IOException {
    try (DerOutputStream tmp = new DerOutputStream()) {
        DerOutputStream bytes = new DerOutputStream();
        bytes.putOID(algid);
        byte val = (byte) contextVal;
        // omit parameter field for ECDSA
        if (!algid.equals(sha224WithEC_oid) && !algid.equals(sha256WithEC_oid) && !algid.equals(sha384WithEC_oid) && !algid.equals(sha512WithEC_oid)) {
            if (params == null) {
                bytes.putNull();
            } else {
                bytes.putDerValue(params);
            }
        }
        DerOutputStream seq = new DerOutputStream();
        seq.write(DerValue.tag_Sequence, bytes);
        tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, val), seq);
        out.write(tmp.toByteArray());
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Example 80 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class AlgorithmId method encode.

// XXXX cleaning required
/**
 * Returns the DER-encoded X.509 AlgorithmId as a byte array.
 * @return the byte array
 * @throws IOException If an error occurred.
 */
public final byte[] encode() throws IOException {
    try (DerOutputStream out = new DerOutputStream()) {
        DerOutputStream bytes = new DerOutputStream();
        bytes.putOID(algid);
        // omit parameter field for ECDSA
        if (!algid.equals(sha224WithEC_oid) && !algid.equals(sha256WithEC_oid) && !algid.equals(sha384WithEC_oid) && !algid.equals(sha512WithEC_oid)) {
            if (params == null) {
                bytes.putNull();
            } else
                bytes.putDerValue(params);
        }
        out.write(DerValue.tag_Sequence, bytes);
        return out.toByteArray();
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Aggregations

DerOutputStream (org.mozilla.jss.netscape.security.util.DerOutputStream)141 IOException (java.io.IOException)37 BigInt (org.mozilla.jss.netscape.security.util.BigInt)13 DerValue (org.mozilla.jss.netscape.security.util.DerValue)8 ObjectIdentifier (org.mozilla.jss.netscape.security.util.ObjectIdentifier)8 CRLException (java.security.cert.CRLException)7 CertificateException (java.security.cert.CertificateException)7 InvalidKeyException (java.security.InvalidKeyException)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ANY (org.mozilla.jss.asn1.ANY)5 InvalidBERException (org.mozilla.jss.asn1.InvalidBERException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 KeyFactory (java.security.KeyFactory)3 SignatureException (java.security.SignatureException)3 CertificateEncodingException (java.security.cert.CertificateEncodingException)3 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)3 NoSuchProviderException (java.security.NoSuchProviderException)2 Provider (java.security.Provider)2 PublicKey (java.security.PublicKey)2