saadi06 2 Junior Poster in Training

Hi,
I am trying to make a smime pk7s file using openssl and send the attachment as an email. I am trying to encrypt a file with a public key and and sign that file. I am using makemime library for the enryption of my xml file.I want to create a smime.p7m file which when decrypted should look something like this

Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-1; 
    boundary="----=_Part_433_1450396784.1383571861622"

------=_Part_433_1450396784.1383571861622
Content-Type: message/rfc822

Date: Mon, 4 Nov 2013 13:31:01 +0000 (UTC)
From: sender@abc.com
To: reciever@gmail.com
Message-ID: <JavaMail.tomcat7@.compute.internal>
Subject: Message test
MIME-Version: 1.0
Content-Type: multipart/mixed; 
    boundary="----=_Part_430_1547498230.1383571861618"

------=_Part_430_1547498230.1383571861618
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Message test
------=_Part_430_1547498230.1383571861618
Content-Type: text/xml; name=Sample1.xml
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=Sample1.xml

PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4NCjxDbGluaWNhbERvY3VtZW50
IHhtbG5zPSJ1cm46aGw3LW9yZzp2MyIgeG1sbnM6c2R0Yz0idXJuOmhsNy1vcmc6c2R0YyIgeG1s
bnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZSIgeHNpOnNj
aGVtYUxvY2F0aW9uPSJ1cm46aGw3LW9yZzp2MyBDMzJfQ0RBLnhzZCI+DQoJPHJlYWxtQ29kZSBj
b2RlPSJVUyIvPg0KCTx0eXBlSWQgcm9vdD0iMi4xNi44NDAuMS4xMTM4ODMuMS4zIiBleHRlbnNp
b249IlBPQ0RfSEQwMDAwNDAiLz4NCgk8dGVtcGxhdGVJZCByb290PSIyLjE2Ljg0MC4xLjExMzg4
My4zLjI3LjE3NzYiIGFzc2lnbmluZ0F1dGhvcml0eU5hbWU9IkNEQS9SMiIvPg0KCTwhLS10ZW1w
bGF0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29kZSBjb2RlPSJlbi1VUyIv
Pg0KCTxyZWNvcmRUYXJnZXQ+DQoJCTxwYXRpZW50Um9sZT4NCgkJCTxpZCBleHRlbnNpb249Ijk5
OTY3OTk1ODkiIHJvb3Q9Ik1FVFJPQ0xJTklDIiBhc3NpZ25pbmdBdXRob3JpdHlOYW1lPSJNZXRy
b3BvbGl0YW4gQ2xpbmljIi8+DQoJCQk8YWRkcj4NCgkJCQk8c3RyZWV0QWRkcmVzc0xpbmU+NTcz

------=_Part_430_1547498230.1383571861618--

------=_Part_433_1450396784.1383571861622
Content-Type: application/pkcs7-signature; name=smime.p7s; smime-type=signed-data
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
Content-Description: S/MIME Cryptographic Signature

MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIAwggQWMIID
f6ADAgECAghIQFcMaAiasTANBgkqhkiG9w0BAQUFADCBpDEkMCIGCSqGSIb3DQEJARYVdHJhbnNw
b3J0LXRlc3Rpbmcub3JnMR4wHAYDVQQDDBV0cmFuc3BvcnQtdGVzdGluZy5vcmcxCzAJBgNVBAYT
AlVTMQswCQYDVQQIDAJNRDEVMBMGA1UEBwwMR2FpdGhlcnNidXJnMSswKQYDVQQKDCJ0cmFuc3Bv
cnQtdGVzdGluZy5vcmcgVHJ1c3QgQW5jaG9yMB4XDTEzMDIyODE5NDExNloXDTIzMDIyMzE5NDEx
NlowgaMxKDAmBgkqhkiG9w0BCQEWGXR0dC50cmFuc3BvcnQtdGVzdGluZy5vcmcxIjAgBgNVBAMM
GXR0dC50cmFuc3BvcnQtdGVzdGluZy5vcmcxCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJNRDEVMBMG
A1UEBwwMR2FpdGhlcnNidXJnMSIwIAYDVQQKDBlUVFQgdHJhbnNwb3J0LXRlc3Rpbmcub3JnMIGf
MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCJNSAD5/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ob3ICCEhAVwxoCJqxMAkGBSsOAwIaBQCgggF1MBgG
CSqGSIb3DQEJAzELBgkqhkiG9w0BBwEwHAYJKoZIhvcNAQkFMQ8XDTEzMTEwNDEzMzEwMVowIwYJ
KoZIhvcNAQkEMRYEFKTJWdttGQXVT6K3GMAxBHIGND0pME8GCSqGSIb3DQEJDzFCMEAwCgYIKoZI
hvcNAwcwDgYIKoZIhvcNAwICAgCAMAcGBSsOAwIHMAsGCSqGSIb3DQEHATAMBgoqhkiG9w0BCRYB
MIHEBgsqhkiG9w0BCRACCzGBtKCBsTCBpDEkMCIGCSqGSIb3DQEJARYVdHJhbnNwb3J0LXRlc3Rp
bmcub3JnMR4wHAYDVQQDDBV0cmFuc3BvcnQtdGVzdGluZy5vcmcxCzAJBgNVBAYTAlVTMQswCQYD
VQQIDAJNRDEVMBMGA1UEBwwMR2FpdGhlcnNidXJnMSswKQYDVQQKDCJ0cmFuc3BvcnQtdGVzdGlu
Zy5vcmcgVHJ1c3QgQW5jaG9yAghIQFcMaAiasTANBgkqhkiG9w0BAQEFAASBgGOZS0eTh9I085VV
zdJn1o1N46SCnBQU0ODpfatZ9NkPYcvlXa2njNQd+G4aZi0AW5xA1ZFMHQ6gk9hzdRtuHcxFH47k
zzB/GGUu12jvXqrstJKbTvU1/ON0oc9loXwcoz9jfd6RxhFE1ieUMu0GZlkE9ha1RqSiZ6g8UIxb
/7/aAAAAAAAA
------=_Part_433_1450396784.1383571861622--

What I am able to achieve is that I am using makemime to encrypt the data that is the content of my xml file and then I create the data first in the same format that is mentioned above and I try to create the smime.p7m file. Can any one tell me that is this the correct way to encrypt the file or is there any ssl command through which I can make the content of my encrypted file look exactly same. I am using OpenSSL 0.9.8o version on windows base enviornment.
Thanks in advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.