I generated a .pem certificate in a self-signed way with the private key inside. I have to apply the signature on a pdf file to test a code that actually checks that the signature is invalid.
I need a way to do this either in c# or with OpenSSL.
For example with OpenSSL I tried to use this
openssl cms -nosmimecap -md sha256 -binary -nodetach -cades -outform DER -sign -signer miocertificato.pem -inkey miachiaveprivata.key -in filedafirmare.pdf -out fileformato.pdf.p7m
but I had this error "cms: Unrecognized flag cades".
OpenSSL is not capable of doing this!
In C# you can modify the bytes of the PDF as specified.
Alternatively you can build on open source like iText Sharp, as in the question.
Or you can look out for commercial components - most of them support digital signatures.