We receive a lot of P7M files, "wrapped CAdES" only.
We need to extract content from P7M.
I am able to do manually using an hex editor, cutting before and after the PDF content, or using openssl
command.
Is there a way to do it using PHP? I can see OpenSSL extension but I'm not able to figure out a simple extraction method.
Note: Content is wrapped, not crypted.
I am able to find Python only answers, like the following:
I found a perfect package on github
https://github.com/filippotoso/p7m-extractor
It does exactly what I need. And it works in Laravel (I tried it on laravel 9)
use FilippoToso\P7MExtractor\P7M;
.....
$success = (new P7M("<full path to openssl executable>"))
->setSource($pathToFileToExtract)
->setDestination($pathToExtractedPdf)
->save()
;
It requires your system has an openssl.exe already installed. It easy to find a windows build here: https://slproweb.com/products/Win32OpenSSL.html