Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Encryption and Decryption between C++ and C#

Encryption and Decryption between C++ and C#

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++sysadminsecurityhelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vipin_nvk
    wrote on last edited by
    #1

    Hi We need to encrypt a string and send across to a web service in C# over the internet. The webservice would decrpt the string and process it. How can I ensure that I use common encryption/decryption algorithms on both the client (C++, win32) and server side (C#) I have tried to build a C++ dll with the enc/dec interfaces and give it to the C# service to call them using marshaling, but I am failing to get the desired result. Please help Thanks in advance

    O 1 Reply Last reply
    0
    • V vipin_nvk

      Hi We need to encrypt a string and send across to a web service in C# over the internet. The webservice would decrpt the string and process it. How can I ensure that I use common encryption/decryption algorithms on both the client (C++, win32) and server side (C#) I have tried to build a C++ dll with the enc/dec interfaces and give it to the C# service to call them using marshaling, but I am failing to get the desired result. Please help Thanks in advance

      O Offline
      O Offline
      Orjan Westin
      wrote on last edited by
      #2

      Use a standard algorithm. C#/.NET has a fair few in the System.Security.Cryptography namespace. On the C++ side you just need to use the same algorithm. Check out Crypto++ for good and free implementations. There is no need to have the exact same source code used in both C++ and C#, provided you use a well documented and standardised algorithm.

      V 1 Reply Last reply
      0
      • O Orjan Westin

        Use a standard algorithm. C#/.NET has a fair few in the System.Security.Cryptography namespace. On the C++ side you just need to use the same algorithm. Check out Crypto++ for good and free implementations. There is no need to have the exact same source code used in both C++ and C#, provided you use a well documented and standardised algorithm.

        V Offline
        V Offline
        vipin_nvk
        wrote on last edited by
        #3

        Thanx Orjan Cant we use Microsoft Cryptographic API's on the C++ win32 application for the same? Like the one here http://msdn.microsoft.com/en-us/library/aa380255(v=VS.85).aspx[^]

        O M 2 Replies Last reply
        0
        • V vipin_nvk

          Thanx Orjan Cant we use Microsoft Cryptographic API's on the C++ win32 application for the same? Like the one here http://msdn.microsoft.com/en-us/library/aa380255(v=VS.85).aspx[^]

          O Offline
          O Offline
          Orjan Westin
          wrote on last edited by
          #4

          CAPICOM has been deprecated by Microsoft, and is not available on Windows 7. I wouldn't use it myself since it's limited in capability and a bit of a mess to use, if I recall correctly (haven't looked at it for years). Oh, it says here that "only CAPICOM can decrypt a CAPICOM EncryptedData object" which would rule it out for you, if you need it to interop with C# (unless you wrap it in a DLL and call that from the server - was that what you tried?) Since they recommend you use .NET crypto for any new development, you might as well create a simple DLL in C# or C++/CLI that exposes the same to the desktop application. (Which is the opposite of what you've tried already, but this way around it's likely easier to test and debug on a desktop.)

          V 1 Reply Last reply
          0
          • O Orjan Westin

            CAPICOM has been deprecated by Microsoft, and is not available on Windows 7. I wouldn't use it myself since it's limited in capability and a bit of a mess to use, if I recall correctly (haven't looked at it for years). Oh, it says here that "only CAPICOM can decrypt a CAPICOM EncryptedData object" which would rule it out for you, if you need it to interop with C# (unless you wrap it in a DLL and call that from the server - was that what you tried?) Since they recommend you use .NET crypto for any new development, you might as well create a simple DLL in C# or C++/CLI that exposes the same to the desktop application. (Which is the opposite of what you've tried already, but this way around it's likely easier to test and debug on a desktop.)

            V Offline
            V Offline
            vipin_nvk
            wrote on last edited by
            #5

            Thanx Orjan I will try that out

            1 Reply Last reply
            0
            • V vipin_nvk

              Thanx Orjan Cant we use Microsoft Cryptographic API's on the C++ win32 application for the same? Like the one here http://msdn.microsoft.com/en-us/library/aa380255(v=VS.85).aspx[^]

              M Offline
              M Offline
              MicroVirus
              wrote on last edited by
              #6

              You could also look at Cryptography API: Next Generation[^] which is the replacement for CAPI. I have no idea how 'good' it is, but I do know that the .NET framework has some CNG implementations of various standard algorithms. Though, I must admit, it might just be easier to write the C# dll and interop with that.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups