Encrypt a big file using openssl smime

user2216168 picture user2216168 · Sep 20, 2013 · Viewed 13.6k times · Source

I have generated a local certificate in my system and I am trying to encrypt a file through smime. But when I run the command it give me error Unable to load certificate Expecting trusted certificate Error 1024. This is my script that I am trying to run

openssl  smime  -encrypt -aes256  -in  ABC.xml  -binary  -outform DEM  -out  DEF.xml  test.pem

Test.pem is my public key. Can anyone tell me that how can I bypass this section and generate a file. Thanks in advance.

Answer

Iridium picture Iridium · Sep 20, 2013

You don't indicate how you created your test.pem, but here's the sequence of commands you might be able to use:

Create a new key and a certificate request (you will be prompted for additional information to complete the request):

openssl req -newkey rsa:2048 -keyout privkey.pem -out req.pem

Self-sign the certificate request to create a certificate

openssl x509 -req -in req.pem -signkey privkey.pem -out cert.pem

(You can delete req.pem at this point if you wish)

Encrypt the file using the newly generated certificate:

openssl smime -encrypt -aes256 -in ABC.xml -binary -outform DER -out DEF.xml cert.pem

The file can then be decrypted using:

openssl smime -decrypt -in DEF.xml -inform DER -inkey privkey.pem -out GHI.xml