Mashup: Key Blobs, Win32 CryptoAPI and .NET

A while back I had the pleasure of getting more in touch with my crypto side. It was, and still is, very under-developed. Cryptography (and the surrounding use cases) seems to be one of those elite-like skills that people can spend lifetimes researching and learning more about. Therefore, it generally is difficult to pick up when you run into for the first time.

I had used simple encryption functions with different languages before, but never to the extent at which this project took me. In this case, I had a written a pure C++, Windows dll which produced a session key that needed to be consumed by a .NET application.

It seems that one solution to the complexity (like the .NET framework’s solution) is to make pretty wrappers around the system calls so one doesn’t totally freak out. While this is nice and I think a very natural progression of a framework it actually made it more difficult to solve the problem. Not only is the documentation horrendous for this, it would appear that .NET’s implementation is not really in sync with the native CryptoAPI’s. 

Aside from battling through the documentation over at MSDN, Google searches were coming up blank on this. While working through things I ended up posting the question to Stack Overflow. If any of this stuff interests you at all you can check it out over there. I also ended up posting a solution to the problem once I figured things out, as the help at the overfloweth of stacks was limited.

It’s all very anti-climactic but felt since there was no straight answer anywhere on the web, I would try and share mine in hopes of helping some other lost geeky sole.

-

If you enjoyed this post, it would be rock-a-licious if you subscribed to future updates via rss.

~ by Scott Saad on December 30, 2008.

5 Responses to “Mashup: Key Blobs, Win32 CryptoAPI and .NET”

  1. Hi,
    Thanks for the post. I am exactly in the same situation that you outlined in your post.
    Would it be possible for you to share source code for both C++/C#?
    Thanks and much appreciated.

    • Hello,

      Thanks for leaving a comment. I would be happy to post more code if necessary. Were you able to check out the answer I posted over on Stack Overflow? It definitively is more verbose than the post here. This post was more of an introduction into the solution. Please let me know if you need more details after reading the solution on Stack Overflow. I would be happy to help in any way.

      • Yes I did. Your post helped me a great deal in understanding the nuances of cross language issues. I am looking for a working sample for both the C++/C# side. You can contact me at gana2k1@gmail.com.
        I am using win32 crypto api to encrypt some data, base64 encode it and transmit it to the server where c# services need to decrypt and validate. I am having a little difficulty in matching the C# decryption bit.

  2. I will attempt to round up some code example(s).

  3. Also, it might be beneficial to post some of the details describing the problem(s) you’re having. It’s something I struggled with for sometime and any problem(s) you encounter can probably be learned from by many others, including myself.

Leave a Reply