Search in sources :

Example 1 with Base64OutputStream

use of com.github.zhenwei.pkix.mime.encoding.Base64OutputStream in project LinLong-Java by zhenwei1108.

the class SMIMEEnvelopedWriter method getContentStream.

public OutputStream getContentStream() throws IOException {
    headers.dumpHeaders(mimeOut);
    mimeOut.write(Strings.toByteArray("\r\n"));
    try {
        OutputStream backing = mimeOut;
        if ("base64".equals(contentTransferEncoding)) {
            backing = new Base64OutputStream(backing);
        }
        OutputStream main = envGen.open(SMimeUtils.createUnclosable(backing), outEnc);
        return new ContentOutputStream(main, backing);
    } catch (CMSException e) {
        throw new MimeIOException(e.getMessage(), e);
    }
}
Also used : OutputStream(java.io.OutputStream) Base64OutputStream(com.github.zhenwei.pkix.mime.encoding.Base64OutputStream) Base64OutputStream(com.github.zhenwei.pkix.mime.encoding.Base64OutputStream) MimeIOException(com.github.zhenwei.pkix.mime.MimeIOException) CMSException(com.github.zhenwei.pkix.cms.CMSException)

Example 2 with Base64OutputStream

use of com.github.zhenwei.pkix.mime.encoding.Base64OutputStream in project LinLong-Java by zhenwei1108.

the class SMIMESignedWriter method getContentStream.

/**
 * Return a content stream for the signer - note data written to this stream needs to properly
 * canonicalised if necessary.
 *
 * @return an output stream for data to be signed to be written to.
 * @throws IOException on a stream error.
 */
public OutputStream getContentStream() throws IOException {
    headers.dumpHeaders(mimeOut);
    mimeOut.write(Strings.toByteArray("\r\n"));
    if (boundary == null) {
        // TODO: new ContentOutputStream(sigGen.open(mimeOut, true), mimeOut);
        return null;
    } else {
        mimeOut.write(Strings.toByteArray("This is an S/MIME signed message\r\n"));
        mimeOut.write(Strings.toByteArray("\r\n--"));
        mimeOut.write(Strings.toByteArray(boundary));
        mimeOut.write(Strings.toByteArray("\r\n"));
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        Base64OutputStream stream = new Base64OutputStream(bOut);
        return new ContentOutputStream(sigGen.open(stream, false, SMimeUtils.createUnclosable(mimeOut)), mimeOut, bOut, stream);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Base64OutputStream(com.github.zhenwei.pkix.mime.encoding.Base64OutputStream)

Aggregations

Base64OutputStream (com.github.zhenwei.pkix.mime.encoding.Base64OutputStream)2 CMSException (com.github.zhenwei.pkix.cms.CMSException)1 MimeIOException (com.github.zhenwei.pkix.mime.MimeIOException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1