extract ciphertext from encrypted SMIME file

the main question of this message is how to get the true ciphertext from S/MIME file?

I created RSA keys and encrypted a message with S/MIME as follow :

1) generate private key : openssl genrsa -out maCle.pem 1024

2) create certificate(public key) : openssl req -new -x509 -key privkey.pem -out certif.pem -days 1095

3) encrypt using smime : openssl smime -encrypt -in plaintext -text -out mail.msg certif.pem


mail.msg looks like:

MIME-Version: 1.0
Content-Disposition: attachment; filename="smime.p7m"
Content-Type: application/x-pkcs7-mime; smime-type=enveloped-data; name="smime.p7m"
Content-Transfer-Encoding: base64

A1UEBhMCRlIxEjAQBgNVBAgMCUZSQU5DRVNFQjEQMA4GA1UEBwwHQ0lUWVNFQjEP
MA0GA1UECgwGT1JHU0VCMRQwEgYDVQQLDAtPUkdVTklUTkFNRTEPMA0GA1UEAwwG
U0VCU0VCMRkwFwYJKoZIhvcNAQkBFgpTRUJTRUJBRERSAgkAvllfFuC1s/owDQYJ
KoZIhvcNAQEBBQAEgYCzD+ShH91R3PEFTFJzcmW5Ie91AT9vHHCVJ1Sb78/oUHVi
PjS3PJyMD55MWGX+FmC/XYxtMNROP6CJ4nQIh6CmQIzXse/Yvg8WQOEJepC6AmDS
BgkqhkiG9w0BBwEwGgYIKoZIhvcNAwIwDgICAKAECBUxiu2WmkuFgCjdkDzatfYg
YwvXLmFl135Txjb0GEfl5EhV2zvXB6PLMFscOa6SOioR


when I decode the base64 from mail.msg I can see informations that are in my certificate (certif.pem). So it seems mail.msg contains a certificate which is NOT encrypted (is that right?) So how can I extract this certificate and how can I extract the true ciphertext that matches with my plaintext?

I thought the certificate in mail.msg was the same in certif.pem but the beginning doesn't match except the first three characters :

certif.pem : MIIC3DCCAkWgAwI...
mail.msg   : MIIBnQYJKoZIhvc...


so what is this certificate?

• It doesn't contain the cert, it contains the IssuerAndSerialNumber to identify the cert so a recipient with multiple keys knows which to use and for a message with multiple recipients each recipient knows which one to use. See 6.2.1 in ietf.org/rfc/rfc3369.txt . IssuerSN is only part of RecipInfo which is only part of the overall message; there are lots of other pieces in there. – dave_thompson_085 Nov 17 '14 at 7:41

openssl smime -in msg -pk7out -out msg.pk7