FileOutputStream fos = new FileOutputStream("C:\\foo.der"); fos.write(pkcs7.getEncoded()); fos.close();
    public byte[] createPKCS7(Certificate cert) throws SignRequestSignatureException {        debug(">createPKCS7()");        // First verify that we signed this certificate        try {            if (cert != null)                cert.verify(signingDevice.getPublicSignKey(), signingDevice.getProvider());        } catch (Exception e) {            throw new SignRequestSignatureException("Cannot verify certificate in createPKCS7(), did I sign this?");        }        Certificate[] chain = getCertificateChain();        Certificate[] certs;        if (cert != null) {            certs = new Certificate[chain.length+1];            certs[0] = cert;            for (int i=0;i<chain.length;i++)                certs[i+1] = chain[i];        } else {            certs = chain;        }        try {            PKCS7SignedData pkcs7 =                new PKCS7SignedData(                    signingDevice.getPrivateSignKey(),                    certs,                    "SHA1",                    signingDevice.getProvider());            debug("<createPKCS7()");            FileOutputStream fos = new FileOutputStream("C:\\foo.der");            fos.write(pkcs7.getEncoded());            fos.close();            return pkcs7.getEncoded();        } catch (Exception e) {            throw new EJBException(e);        }    } // createPKCS7