Example usage for com.itextpdf.text.pdf.security PdfPKCS7 getDigestAlgorithm

List of usage examples for com.itextpdf.text.pdf.security PdfPKCS7 getDigestAlgorithm

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf.security PdfPKCS7 getDigestAlgorithm.

Prototype

public String getDigestAlgorithm() 

Source Link

Document

Get the algorithm used to calculate the message digest, e.g.

Usage

From source file:org.opencps.pki.PdfSignatureInfo.java

License:Open Source License

/**
 * Constructor/*from ww w  .  j a  v  a2s . c  o m*/
 */
public PdfSignatureInfo(PdfPKCS7 pkcs7) {
    super(pkcs7.getSigningCertificate(), new CertificateInfo(pkcs7.getSigningCertificate()),
            pkcs7.getSignDate(), pkcs7.getTimeStampDate(), pkcs7.getDigestAlgorithm(),
            pkcs7.getHashAlgorithm());
    this.pkcs7 = pkcs7;
}

From source file:org.roda.common.certification.PDFSignatureUtils.java

private static StringBuilder getExtractionInformation(AcroFields fields, ArrayList<?> names,
        Path outputContents, String filename) throws IOException {

    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < names.size(); i++) {
        String name = (String) names.get(i);
        Item item = fields.getFieldItem(name);

        PdfDictionary widget = item.getWidget(0);
        PdfDictionary infoDictionary = widget.getAsDict(PdfName.V);
        sb.append("<signature>\n");

        try {//from   www  .ja v a  2s  .com
            PdfPKCS7 pk = fields.verifySignature(name);
            sb = addElementToExtractionResult(sb, "name", name);
            sb = addElementToExtractionResult(sb, "sign-name", pk.getSignName());
            sb = addElementToExtractionResult(sb, "version", Integer.toString(pk.getVersion()));
            sb = addElementToExtractionResult(sb, "reason", pk.getReason());
            sb = addElementToExtractionResult(sb, "location", pk.getLocation());

            SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");

            if (pk.getTimeStampDate() != null) {
                String timestamp = formatter.format(pk.getTimeStampDate().getTime());
                sb = addElementToExtractionResult(sb, "timestamp-time", timestamp);
            }

            if (pk.getSignDate() != null) {
                String sign = formatter.format(pk.getSignDate().getTime());
                sb = addElementToExtractionResult(sb, "sign-time", sign);
            }

            sb = addElementToExtractionResult(sb, "digest-algorithm", pk.getDigestAlgorithm());
            sb = addElementToExtractionResult(sb, "hash-algorithm", pk.getHashAlgorithm());
            sb = addElementToExtractionResult(sb, "covers-whole-document",
                    Boolean.toString(fields.signatureCoversWholeDocument(name)));
            sb = addElementToExtractionResult(sb, "ft", widget.get(PdfName.FT).toString());

            if (infoDictionary.contains(PdfName.CONTACTINFO))
                sb = addElementToExtractionResult(sb, "contact-info",
                        infoDictionary.getAsString(PdfName.CONTACTINFO).toString());

            if (infoDictionary.contains(PdfName.FILTER))
                sb = addElementToExtractionResult(sb, "filter", infoDictionary.get(PdfName.FILTER).toString());

            if (infoDictionary.contains(PdfName.SUBFILTER))
                sb = addElementToExtractionResult(sb, "subfilter",
                        infoDictionary.get(PdfName.SUBFILTER).toString());

            if (infoDictionary.contains(PdfName.LOCK))
                sb = addElementToExtractionResult(sb, "lock", "true");

            if (infoDictionary.contains(PdfName.CONTENTS)) {
                PdfString elementName = infoDictionary.getAsString(PdfName.CONTENTS);
                Files.write(outputContents, elementName.toUnicodeString().getBytes());
                sb = addElementToExtractionResult(sb, "contents", filename + ".pkcs7");
            }

        } catch (NoSuchFieldError e) {
            LOGGER.warn("DS information extraction did not execute properly");
        }

        sb.append("</signature>");
    }

    return sb;
}

From source file:org.roda.core.plugins.plugins.characterization.PDFSignatureUtils.java

private static StringBuilder getExtractionInformation(AcroFields fields, ArrayList<?> names,
        Path outputContents, String filename) throws IOException {
    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < names.size(); i++) {
        String name = (String) names.get(i);
        Item item = fields.getFieldItem(name);

        PdfDictionary widget = item.getWidget(0);
        PdfDictionary infoDictionary = widget.getAsDict(PdfName.V);
        sb.append("<signature>\n");

        try {//ww  w.  j av a  2  s . com
            PdfPKCS7 pk = fields.verifySignature(name);
            sb = addElementToExtractionResult(sb, "name", name);
            sb = addElementToExtractionResult(sb, "sign-name", pk.getSignName());
            sb = addElementToExtractionResult(sb, "version", Integer.toString(pk.getVersion()));
            sb = addElementToExtractionResult(sb, "reason", pk.getReason());
            sb = addElementToExtractionResult(sb, "location", pk.getLocation());

            SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");

            if (pk.getTimeStampDate() != null) {
                String timestamp = formatter.format(pk.getTimeStampDate().getTime());
                sb = addElementToExtractionResult(sb, "timestamp-time", timestamp);
            }

            if (pk.getSignDate() != null) {
                String sign = formatter.format(pk.getSignDate().getTime());
                sb = addElementToExtractionResult(sb, "sign-time", sign);
            }

            sb = addElementToExtractionResult(sb, "digest-algorithm", pk.getDigestAlgorithm());
            sb = addElementToExtractionResult(sb, "hash-algorithm", pk.getHashAlgorithm());
            sb = addElementToExtractionResult(sb, "covers-whole-document",
                    Boolean.toString(fields.signatureCoversWholeDocument(name)));
            sb = addElementToExtractionResult(sb, "ft", widget.get(PdfName.FT).toString());

            if (infoDictionary.contains(PdfName.CONTACTINFO))
                sb = addElementToExtractionResult(sb, "contact-info",
                        infoDictionary.getAsString(PdfName.CONTACTINFO).toString());

            if (infoDictionary.contains(PdfName.FILTER))
                sb = addElementToExtractionResult(sb, "filter", infoDictionary.get(PdfName.FILTER).toString());

            if (infoDictionary.contains(PdfName.SUBFILTER))
                sb = addElementToExtractionResult(sb, "subfilter",
                        infoDictionary.get(PdfName.SUBFILTER).toString());

            if (infoDictionary.contains(PdfName.LOCK))
                sb = addElementToExtractionResult(sb, "lock", "true");

            if (infoDictionary.contains(PdfName.CONTENTS)) {
                PdfString elementName = infoDictionary.getAsString(PdfName.CONTENTS);
                Files.write(outputContents, elementName.toUnicodeString().getBytes());
                sb = addElementToExtractionResult(sb, "contents", filename + ".pkcs7");
            }

        } catch (NoSuchFieldError e) {
            LOGGER.warn("DS information extraction did not execute properly");
        }

        sb.append("</signature>");
    }

    return sb;
}