Search in sources :

Example 11 with DerOutputStream

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

the class X509CertInfo method encode.

/**
 * Appends the certificate to an output stream.
 *
 * @param out An output stream to which the certificate is appended.
 * @param ignoreCache Whether to ignore the internal cache when encoding.
 *            (the cache can easily become out of date).
 */
public void encode(OutputStream out, boolean ignoreCache) throws IOException, CertificateException {
    if (ignoreCache || (rawCertInfo == null)) {
        DerOutputStream tmp = new DerOutputStream();
        emit(tmp);
        rawCertInfo = tmp.toByteArray();
    }
    out.write(rawCertInfo);
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Example 12 with DerOutputStream

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

the class X509CertInfo method emit.

/*
     * Marshal the contents of a "raw" certificate into a DER sequence.
     */
private void emit(DerOutputStream out) throws CertificateException, IOException {
    DerOutputStream tmp = new DerOutputStream();
    // version number, iff not V1
    version.encode(tmp);
    // Encode serial number, issuer signing algorithm, issuer name
    // and validity
    serialNum.encode(tmp);
    algId.encode(tmp);
    issuer.encode(tmp);
    interval.encode(tmp);
    // Encode subject (principal) and associated key
    subject.encode(tmp);
    pubKey.encode(tmp);
    // Encode issuerUniqueId & subjectUniqueId.
    if (issuerUniqueId != null) {
        issuerUniqueId.encode(tmp);
    }
    if (subjectUniqueId != null) {
        subjectUniqueId.encode(tmp);
    }
    // Write all the extensions.
    if (extensions != null) {
        extensions.encode(tmp);
    }
    // Wrap the data; encoding of the "raw" cert is now complete.
    out.write(DerValue.tag_Sequence, tmp);
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Example 13 with DerOutputStream

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

the class X509Key method encode.

/*
     * Produce SubjectPublicKey encoding from algorithm id and key material.
     */
static void encode(DerOutputStream out, AlgorithmId algid, byte[] key) throws IOException {
    DerOutputStream tmp = new DerOutputStream();
    algid.encode(tmp);
    tmp.putBitString(key);
    out.write(DerValue.tag_Sequence, tmp);
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Example 14 with DerOutputStream

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

the class X509Key method encode.

/**
 * Returns the DER-encoded form of the key as a byte array.
 *
 * @exception InvalidKeyException on encoding errors.
 */
public byte[] encode() throws InvalidKeyException {
    if (encodedKey == null) {
        try {
            DerOutputStream out;
            out = new DerOutputStream();
            encode(out);
            encodedKey = out.toByteArray();
        } catch (IOException e) {
            throw new InvalidKeyException("IOException : " + e.getMessage());
        }
    }
    return copyEncodedKey(encodedKey);
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException)

Example 15 with DerOutputStream

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

the class RSAPSSAlgorithmParameters method encode.

private void encode(DerOutputStream out) throws IOException {
    try (DerOutputStream tmp = new DerOutputStream();
        DerOutputStream mgf = new DerOutputStream();
        DerOutputStream seq1 = new DerOutputStream();
        DerOutputStream intStream = new DerOutputStream()) {
        // Hash algorithm
        hashAlg.derEncodeWithContext(tmp, 0);
        // Mask Gen Function Sequence
        mgf.putOID(maskGenFunc.getOID());
        // MGF hash alg is the same as the hash Alg at this point.
        hashAlg.encode(mgf);
        seq1.write(DerValue.tag_Sequence, mgf);
        tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 1), seq1);
        // Salt Length
        intStream.putInteger(saltLen);
        tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 2), intStream);
        // Ignore trailer field, it never changes over all sequence tags
        out.write(DerValue.tag_Sequence, tmp);
        byte[] data = 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