none
How to encrypt message in WCF by writing code RRS feed

  • Question

  • i want to develop a wcf service which will send encrypted message / response to client and client will decrypt it and same way client will send data in encrypted format which wcf service decrypt it before taking any action.

    i hard that wcf has message inspector which can do it but not getting any easy understanding sample code to achieve the same. so please give me a sample code how to achieve it. also give me sample code for both wcf service and client side code.

    thanks

    Tuesday, April 21, 2015 1:02 PM

All replies

  • As per your case,I have shared the corresponding details below :
    First of all your service needs a certificate so that your encryption keys can be exchanged securely.

    So You can create a test service authentication certificate with makecert.exe.
    You also need to ensure that the account your service is running as is able to read the certificate's private key file

    but in practice the security of the service depends on where the certs come from, which authentication mode is used on the binding, and the authentication requirements applied to certs

    Refer the following link about Creating X509 Certificates for WCF :
    http://weblogs.asp.net/cibrax/Creating-X509-Certificates-for-WSE-or-WCF

    Example :
    Service Authentication Certificate

    makecert -sr LocalMachine -ss My -pe -n CN=subject-name -eku 1.3.6.1.5.5.7.3.1 -sky exchange

    Client Authentication Certificate

    makecert -sr LocalMachine -ss My -pe -n CN=subject-name -eku 1.3.6.1.5.5.7.3.2

    Note: simply replace subject-name with any certificate name that makes sense for your service

    Then refer the following link which is having sample code of Encryption in WCF for communications between a client side application and a server-based service application

    http://www.rcs-solutions.com/blog/2008/11/06/CustomAuthenticationAndEncryptionWithWCF.aspx

    Wednesday, April 22, 2015 7:15 AM
  • i am do not want to use certificate for any encryption purpose rather i want to encrypt data in message by code and i will develop a client which will consume the service. so control in my hand to decrypt the message and encrypt message from client side too.

    just tell me how could encrypt decrypt data in message by code in wcf.

    Wednesday, April 22, 2015 7:37 AM