use of com.github.zhenwei.pkix.mime.MimeIOException in project LinLong-Java by zhenwei1108.
the class SMimeParserListener method object.
public void object(MimeParserContext parserContext, Headers headers, InputStream inputStream) throws IOException {
try {
if (headers.getContentType().equals("application/pkcs7-signature") || headers.getContentType().equals("application/x-pkcs7-signature")) {
Map<ASN1ObjectIdentifier, byte[]> hashes = new HashMap<ASN1ObjectIdentifier, byte[]>();
for (int i = 0; i != digestCalculators.length; i++) {
digestCalculators[i].getOutputStream().close();
hashes.put(digestCalculators[i].getAlgorithmIdentifier().getAlgorithm(), digestCalculators[i].getDigest());
}
byte[] sigBlock = Streams.readAll(inputStream);
CMSSignedData signedData = new CMSSignedData(hashes, sigBlock);
signedData(parserContext, headers, signedData.getCertificates(), signedData.getCRLs(), signedData.getAttributeCertificates(), signedData.getSignerInfos());
} else if (headers.getContentType().equals("application/pkcs7-mime") || headers.getContentType().equals("application/x-pkcs7-mime")) {
CMSEnvelopedDataParser envelopedDataParser = new CMSEnvelopedDataParser(inputStream);
envelopedData(parserContext, headers, envelopedDataParser.getOriginatorInfo(), envelopedDataParser.getRecipientInfos());
envelopedDataParser.close();
} else {
content(parserContext, headers, inputStream);
}
} catch (CMSException e) {
throw new MimeIOException("CMS failure: " + e.getMessage(), e);
}
}
use of com.github.zhenwei.pkix.mime.MimeIOException 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);
}
}
Aggregations