Search in sources :

Example 16 with DerOutputStream

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

the class RSAPSSAlgorithmParameters method engineGetEncoded.

@Override
protected byte[] engineGetEncoded() throws IOException {
    DerOutputStream out = new DerOutputStream();
    encode(out);
    return out.toByteArray();
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Example 17 with DerOutputStream

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

the class PKCS8Key method encode.

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

Example 18 with DerOutputStream

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

the class PKCS8Key method encode.

/**
 * Returns the DER-encoded form of the key as a byte array.
 *
 * @exception InvalidKeyException if an encoding error occurs.
 */
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 19 with DerOutputStream

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

the class PKCS9Attributes method generateDerEncoding.

private byte[] generateDerEncoding() throws IOException {
    try (DerOutputStream out = new DerOutputStream()) {
        Object[] attribVals = attributes.values().toArray();
        out.putOrderedSetOf(DerValue.tag_SetOf, castToDerEncoder(attribVals));
        return out.toByteArray();
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Example 20 with DerOutputStream

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

the class PKCS7 method encodeSignedData.

/**
 * Encodes the signed data to a DerOutputStream.
 *
 * @param out the DerOutputStream to write the encoded data to.
 * @exception IOException on encoding errors.
 */
public void encodeSignedData(DerOutputStream out, boolean sort) throws IOException {
    DerOutputStream signedData = new DerOutputStream();
    // version
    signedData.putInteger(version);
    // digestAlgorithmIds
    signedData.putOrderedSetOf(DerValue.tag_Set, digestAlgorithmIds);
    // contentInfo
    contentInfo.encode(signedData);
    // cast to X509CertImpl[] since X509CertImpl implements DerEncoder
    X509CertImpl[] implCerts = new X509CertImpl[certificates.length];
    try {
        for (int i = 0; i < certificates.length; i++) {
            implCerts[i] = (X509CertImpl) certificates[i];
        }
    } catch (ClassCastException e) {
        throw new IOException("Certificates in PKCS7 must be of class " + "org.mozilla.jss.netscape.security.X509CertImpl: " + e.getMessage(), e);
    }
    // to the signed data
    if (sort) {
        signedData.putOrderedSetOf((byte) 0xA0, implCerts);
    } else {
        signedData.putSet((byte) 0xA0, implCerts);
    }
    // no crls (OPTIONAL field)
    // signerInfos
    signedData.putOrderedSetOf(DerValue.tag_Set, signerInfos);
    // making it a signed data block
    DerValue signedDataSeq = new DerValue(DerValue.tag_Sequence, signedData.toByteArray());
    // making it a content info sequence
    ContentInfo block = new ContentInfo(ContentInfo.SIGNED_DATA_OID, signedDataSeq);
    // writing out the contentInfo sequence
    block.encode(out);
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) X509CertImpl(org.mozilla.jss.netscape.security.x509.X509CertImpl) DerValue(org.mozilla.jss.netscape.security.util.DerValue) IOException(java.io.IOException)

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