Encrypt and Decrypt a Message

  1. Encrypt the message using the following command:

›_ Console

Bash
openssl cms -encrypt -in signedRSAmessage.txt -out encryptedRSAsignedmessage.txt TestRSA.cert

The encrypted message will have the following format:

›_ Encrypted Message

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

MIIMFAYJKoZIhvcNAQcDoIIMBTCCDAECAQAxggF5MIIBdQIBADBdMEUxCzAJBgNV
BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
aWRnaXRzIFB0eSBMdGQCFAdGmeMIYrV4twsA8FLt3ZBvn5vdMA0GCSqGSIb3DQEB
...
4QTULf9IDxS7/pxXb0P63ij+jIPB8WRD5hm6uYna/niWxMlEfFlwyBSEK+5VtIRT
z5jrZEplI7a3qsdCYPICWSQWn5oxg1L7uskWBBtwyFrMGHIC9BtMx3wNATix9Ni7
HUoc0oXZyWhjn4jKqdmj2bSrfk2BqU5I
  1. Decrypt the message with the following command:

›_ Console

Bash
openssl cms -decrypt -in encryptedRSAsignedmessage.txt -inkey "pkcs11:token=<token_label>;object=<key_label>" -out decryptedRSAsignedmessage.txt