# .Net integration using .pem certificate

**URL:** <https://community.solace.com/t/net-integration-using-pem-certificate/300>\
**Category:** General Discussions\
**Tags:** net, security, c\
**Created:** [June 23, 2020, 6:39am UTC](https://community.solace.com/t/net-integration-using-pem-certificate/300 "2020-06-23T06:39:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aalok](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@aalok](https://community.solace.com/u/aalok)\
**Post date:** [June 23, 2020, 6:39am UTC](https://community.solace.com/t/net-integration-using-pem-certificate/300/1 "2020-06-23T06:39:09Z")

</div>

Hello,  
I’m looking for some help on how to import .pem certificate and use it .Net code.  
Any help or sample implementation for reference will be appreciated.

---

<div class="post-metadata">

**Author:** ![arih](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/arih/32/130_2.png) [@arih](https://community.solace.com/u/arih)\
**Post date:** [July 3, 2020, 1:54pm UTC](https://community.solace.com/t/net-integration-using-pem-certificate/300/2 "2020-07-03T13:54:51Z")

</div>

Hello,  
I’d start from this sample: [C#/.NET Tutorials](https://solace.com/samples/solace-samples-dotnet/) and then change the Session Properties to something like this:

```
            // Create session properties
            SessionProperties sessionProps = new SessionProperties()
            {
                Host = host,
                VPNName = VPNName,
                // UserName = UserName,
                // Password = Password,
                AuthenticationScheme = AuthenticationSchemes.CLIENT_CERTIFICATE,
                SSLTrustStoreDir = "certs",
                SSLClientCertificateFile = "certs/client.pem",
                SSLClientPrivateKeyFile = "certs/client.key",
                SSLClientPrivateKeyFilePassword = "password",
                CompressionLevel = 0, // 0..9 for more compression, but only usable against appliance
                ReconnectRetries = DefaultReconnectRetries
            };

```

Of course, there are other ways, like using SSLClientCertificate and/or SSLTrustStore directly. API reference can be found here: [SessionProperties Class](https://docs.solace.com/API-Developer-Online-Ref-Documentation/net/html/82816aab-350c-a890-cc35-ac125b35421c.htm)

This doc also might help on the certs part, this one is for REST but quite useful since only the REST part is different then using Solace API. [Two-way SSL Authentication for REST](https://docs.solace.com/Configuring-and-Managing/Two-Way-SSL-Authentication.htm)

And you’d need to have a trust store containing your server CA cert in the trust store dir. In my case, I use this command although I wasn’t very sure about using .jks or .p12 🙂  
`keytool -keystore client-truststore.p12 -alias clientts -import -file server.pem`

hope this helps,  
Ari

---

<div class="post-metadata">

**Author:** ![arih](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/arih/32/130_2.png) [@arih](https://community.solace.com/u/arih)\
**Post date:** [July 3, 2020, 1:56pm UTC](https://community.solace.com/t/net-integration-using-pem-certificate/300/3 "2020-07-03T13:56:53Z")

</div>

oops forgot the doc link: [Two-way SSL Authentication for REST](https://docs.solace.com/Configuring-and-Managing/Two-Way-SSL-Authentication.htm)

---

<div class="post-metadata">

**Author:** ![Aaron](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/aaron/32/843_2.png) [@Aaron](https://community.solace.com/u/Aaron)\
**Post date:** [July 5, 2020, 10:41am UTC](https://community.solace.com/t/net-integration-using-pem-certificate/300/4 "2020-07-05T10:41:07Z")

</div>

Hi @aalok . I actually responded to this during my weekly Office Hours live stream last week, I should have posted my answer sooner. Check it out here: [https://www.youtube.com/watch?v=6fW\_u\_s6RDI&t=1187s](https://www.youtube.com/watch?v=6fW_u_s6RDI&t=1187s)

One other thing to add to Ari’s answer is: head to [https://solace.com/downloads/](https://solace.com/downloads/) and download the .NET distribution, and inside the `ex` folder is a specific `secureSession.cs` sample that you might be interested in.

---

<div class="post-metadata">

**Author:** ![Frankee787](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/frankee787/32/1286_2.png) [@Frankee787](https://community.solace.com/u/Frankee787)\
**Post date:** [May 15, 2022, 3:06pm UTC](https://community.solace.com/t/net-integration-using-pem-certificate/300/5 "2022-05-15T15:06:01Z")

</div>

Hello,  
I too stumbled on this issue and got it resolved with a suggestion provided by @alamkhan786 . Hoping this well help someone in the future  
1st option and disable complete chain verification \>  
&nbsp;// Create session properties

> SessionProperties sessionProps = new SessionProperties()  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Host = host,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VPNName = VPNName,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UserName = UserName,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Password = Password,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ReconnectRetries = DefaultReconnectRetries,  
> &nbsp;&nbsp;&nbsp;&nbsp;SSLValidateCertificate = false  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};  
> 2nd Option - Load the store which has the Trusted CA public certificate \>  
> &nbsp;&nbsp;&nbsp;X509CertificateCollection certificatesCollection = new X509CertificateCollection();  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (StoreLocation storeLocation in (StoreLocation)Enum.GetValues(typeof(StoreLocation)))  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (StoreName storeName in (StoreName) Enum.GetValues(typeof(StoreName)))  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;X509Store store = new X509Store(storeName, storeLocation);  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;store.Open(OpenFlags.OpenExistingOnly);  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (X509Certificate certificate in store.Certificates)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;certificatesCollection.Add(certificate);  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;catch (CryptographicException)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(“No&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{0}, {1}”,&nbsp;&nbsp;store.Name, store.Location);  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine();  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
> Use it during the setup of SessionProperties \>  
> &nbsp;&nbsp;&nbsp;SessionProperties sessionProps = new SessionProperties()  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Host = host,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VPNName = VPNName,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UserName = UserName,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Password = Password,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ReconnectRetries = DefaultReconnectRetries,  
> &nbsp;&nbsp;&nbsp;&nbsp;SSLTrustStore= certificatesCollection&nbsp;  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};

Hope it will help the community.  
Best Regards,  
Franklin

---

<div class="post-metadata">

**Author:** ![Tamimi](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/tamimi/32/2190_2.png) [@Tamimi](https://community.solace.com/u/Tamimi)\
**Post date:** [May 15, 2022, 11:42pm UTC](https://community.solace.com/t/net-integration-using-pem-certificate/300/6 "2022-05-15T23:42:45Z")

</div>

Thanks @Frankee787 for sharing! This is indeed very helpful 🙂

---

<div class="post-metadata">

**Author:** ![alamkhan786](https://yyz1.discourse-cdn.com/solace/user_avatar/community.solace.com/alamkhan786/32/54_2.png) [@alamkhan786](https://community.solace.com/u/alamkhan786)\
**Post date:** [June 15, 2022, 4:44pm UTC](https://community.solace.com/t/net-integration-using-pem-certificate/300/7 "2022-06-15T16:44:03Z")

</div>

Thanks @Frankee787 for sharing
