public boolean verify(DigestCalculatorProvider calculatorProvider) throws CMSException { try { ContentInfo content = digestedData.getEncapContentInfo(); DigestCalculator calc = calculatorProvider.get(digestedData.getDigestAlgorithm()); OutputStream dOut = calc.getOutputStream(); dOut.write(((ASN1OctetString) content.getContent()).getOctets()); return Arrays.areEqual(digestedData.getDigest(), calc.getDigest()); } catch (OperatorCreationException e) { throw new CMSException("unable to create digest calculator: " + e.getMessage(), e); } catch (IOException e) { throw new CMSException("unable process content: " + e.getMessage(), e); } }
/** * Return the digested content * * @return the digested content * @throws CMSException if there is an exception un-compressing the data. */ public CMSProcessable getDigestedContent() throws CMSException { ContentInfo content = digestedData.getEncapContentInfo(); try { return new CMSProcessableByteArray( content.getContentType(), ((ASN1OctetString) content.getContent()).getOctets()); } catch (Exception e) { throw new CMSException("exception reading digested stream.", e); } }
public CMSDigestedData(ContentInfo contentInfo) throws CMSException { this.contentInfo = contentInfo; try { this.digestedData = DigestedData.getInstance(contentInfo.getContent()); } catch (ClassCastException e) { throw new CMSException("Malformed content.", e); } catch (IllegalArgumentException e) { throw new CMSException("Malformed content.", e); } }
public AlgorithmIdentifier getDigestAlgorithm() { return digestedData.getDigestAlgorithm(); }