# How to decrypt S/MIME?

**URL:** <https://forum.xojo.com/t/how-to-decrypt-s-mime/47739>\
**Category:** General\
**Created:** [March 15, 2019, 10:02am UTC](https://forum.xojo.com/t/how-to-decrypt-s-mime/47739 "2019-03-15T10:02:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [March 15, 2019, 10:02am UTC](https://forum.xojo.com/t/how-to-decrypt-s-mime/47739/1 "2019-03-15T10:02:49Z")

</div>

The example at [https://www.example-code.com/xojo/smime\_verify\_signature.asp](https://www.example-code.com/xojo/smime_verify_signature.asp) shows how to decrypt S/MIME. But I think it glosses a bit on how to use the Cert part. Can’t I have multiple certificates? Do I need to find the correct certificate or is this handled automatically?

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [March 15, 2019, 10:36am UTC](https://forum.xojo.com/t/how-to-decrypt-s-mime/47739/2 "2019-03-15T10:36:46Z")

</div>

I have some SMIME functions in [OpenSSLMBS](http://www.monkeybreadsoftware.net/module-opensslmbs.shtml) module. Please take a look.

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [March 15, 2019, 11:13am UTC](https://forum.xojo.com/t/how-to-decrypt-s-mime/47739/3 "2019-03-15T11:13:54Z")

</div>

Here is the example code for decrypting:

[code] dim c as X509MBS = X509MBS.Open(ReadFile(GetFolderItem(“signer.pem”)))  
dim k as PKeyMBS = PKeyMBS.Open(ReadFile(GetFolderItem(“signer.pem”)))  
dim i as string = ReadFile(GetFolderItem(“smencr.txt”))

```
		dim d as string = OpenSSLMBS.SMimePKCS7Decrypt(i, c, k)
		
		WriteFile d, GetFolderItem("encrout.txt")[/code]

```

Where do I get signer.pem? Isn’t this what Cert from the Chilkat plugin manages?

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [March 15, 2019, 11:53am UTC](https://forum.xojo.com/t/how-to-decrypt-s-mime/47739/4 "2019-03-15T11:53:05Z")

</div>

with our plugin you can read PKCS#12 file to get both private key and certificates.  
Or you have them in a pem file like in the example.  
Or you have them in separate files.

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [March 15, 2019, 12:11pm UTC](https://forum.xojo.com/t/how-to-decrypt-s-mime/47739/5 "2019-03-15T12:11:29Z")

</div>

I’m a total newbie in this email encryption stuff. Where do I get the pem file? Doesn’t the mail client manage these files? Shouldn’t the keychain handle the encryption?

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 7:35pm UTC](https://forum.xojo.com/t/how-to-decrypt-s-mime/47739/6 "2020-10-29T19:35:08Z")

</div>


