Pergunta

How can I extract, from a pdf signed file, the PKCS7 package encoded, using either IText or BouncyCastle, so i can either store or validate in another framework? In fact, how can I get, at all, a PKCS7 encoded package from a pdf signed file?

Foi útil?

Solução

A friend of mine helped me on getting the answer.

public static byte[] ExtractPKCS7From(string path)
{
    AcroFields acroFields = new PdfReader(path).AcroFields;
    List<string> names = acroFields.GetSignatureNames();

    foreach(var name in names)
    {
        PdfDictionary dict = acroFields.GetSignatureDictionary(name);
        PdfString contents =
            (PdfString)PdfReader.GetPdfObject(dict.Get(PdfName.CONTENTS));

        return contents.GetOriginalBytes();
    }
    return null;
}

Pretty straight forward, isn't it?

Outras dicas

Code for Java, do whatever you want with the pkcs7 object! :)

PdfReader r = new PdfReader(fOs);
AcroFields af = r.getAcroFields();
ArrayList<String> listNames = af.getSignatureNames();
for(String x : listNames){
    PdfPKCS7 pkcs7 = af.verifySignature(signature);
}

Good luck!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top