Click here to Skip to main content
15,792,721 members
Please Sign up or sign in to vote.
0.00/5 (No votes)

I have created a service where there would be a private cert on the server where i am hosting the service and the client will have public key of it. 
And the client would have a different private key where they will encrypt the message which they send to the endpoint i create and i have the public key for it which i will use to decrypt the message. 
What i have so far in the server config file.

So this one takes care of the main private cert where the service will be hosted. I am not sure where/how to put the public key of the cert where client has/uses the private key to encrypt the message.

What I have tried:

<pre><?xml version="1.0"?>
        <httpRuntime maxRequestLength="2147483647"/>
        <compilation debug="false" strict="false" explicit="true" targetFramework="4.5.2"/>
        <pages controlRenderingCompatibilityVersion="4.0"/>
        <customErrors mode="Off"/>
            <binding name="basicHttpEndPointBinding">
              <security mode="Message">
                <message clientCredentialType="Certificate"/>
          <service behaviorConfiguration="wcfJNet.ServiceBehavior" name="wcfJNetService">
            <endpoint address="" binding="basicHttpBinding" 
                <dns value="xxxxxx" />
            <behavior name="wcfJNet.ServiceBehavior">
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
                <serviceCertificate findValue="0000xx000" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySerialNumber"/>
                  <authentication certificateValidationMode="PeerOrChainTrust"/>
          <add binding="basicHttpsBinding" scheme="https"/>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
        <modules runAllManagedModulesForAllRequests="true"/>
            To browse web app root directory during debugging, set the value below to true.
            Set to false before deployment to avoid disclosing web app folder information.
        <directoryBrowse enabled="true"/>
Updated 7-Jan-20 12:42pm
phil.o 7-Jan-20 17:39pm    
The public key is used to encrypt a message, not the private one. The private key is used to decrypt an encrypted message.

private key is used:
- to sign messages
- to decrypt messages encrypted with public key
public key is used:
- to verify the signatures of messages signed with private key
- to encrypt messages

1 solution

Use https. You just have to create a valid certificate for the server, once done you will have nothing else to worry about.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900