Example usage for org.bouncycastle.util.encoders Base64 decode

List of usage examples for org.bouncycastle.util.encoders Base64 decode

Introduction

In this page you can find the example usage for org.bouncycastle.util.encoders Base64 decode.

Prototype

public static int decode(String data, OutputStream out) throws IOException 

Source Link

Document

decode the base 64 encoded String data writing it to the given output stream, whitespace characters will be ignored.

Usage

From source file:org.jruby.ext.openssl.x509store.PEMInputOutput.java

License:LGPL

/**
 * Reads in a PKCS7 object. This returns a ContentInfo object suitable for use with the CMS
 * API.//from   w ww .j  av  a  2 s.c  o m
 *
 * @return the X509Certificate
 * @throws IOException if an I/O error occured
 */
private static CMSSignedData readPKCS7(BufferedReader in, char[] p, String endMarker) throws IOException {
    String line;
    StringBuilder buf = new StringBuilder();
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();

    while ((line = in.readLine()) != null) {
        if (line.indexOf(endMarker) != -1) {
            break;
        }
        line = line.trim();
        buf.append(line.trim());
        Base64.decode(buf.substring(0, (buf.length() / 4) * 4), bOut);
        buf.delete(0, (buf.length() / 4) * 4);
    }
    if (buf.length() != 0) {
        throw new RuntimeException("base64 data appears to be truncated");
    }
    if (line == null) {
        throw new IOException(endMarker + " not found");
    }
    try {
        ASN1InputStream aIn = new ASN1InputStream(bOut.toByteArray());
        return new CMSSignedData(ContentInfo.getInstance(aIn.readObject()));
    } catch (Exception e) {
        throw new IOException("problem parsing PKCS7 object: " + e.toString());
    }
}