I use Java with BouncyCastle to decrypt and verify p7m s/mime messages. When the private key I have chosen to decrypt the message does NOT match, I get errors from Bouncy Castle like "exception unwrapping key" or "bad padding".
But how can I output the serial number of the certificate which was used to encrypt the message? It would be helpful for the customer to see that he has chosen an old certificate for instance.
Windows offers a console app "certutil" in order to analyze a p7m stream. The serial number and the issuer ist mentioned there:
CMSG_KEY_TRANS_RECIPIENT(1)
CERT_ID_ISSUER_SERIAL_NUMBER(1)
Seriennummer: b33...