use of com.github.zhenwei.pkix.cms.CMSEnvelopedDataParser 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);
}
}
Aggregations