Signature sig = Signature.getInstance(digestAlgorithm + "with" + keyAlgorithm);
sig.initSign(privKey);
sig.update(sigFileContent);
// Create PKCS7 block
PKCS7 pkcs7 = new PKCS7(
new AlgorithmId[]{AlgorithmId.get(digestAlgorithm)},
new ContentInfo(sigFileContent),
certChain,
new SignerInfo[]{new SignerInfo(
(X500Name) certChain[0].getIssuerDN(),
certChain[0].getSerialNumber(),
AlgorithmId.get(digestAlgorithm),
AlgorithmId.get(keyAlgorithm),
sig.sign())
});
ByteArrayOutputStream bout = new ByteArrayOutputStream();
pkcs7.encodeSignedData(bout);
// Write output
ZipOutputStream zout = new ZipOutputStream(
new FileOutputStream(output));
zout.putNextEntry((signed)