This is a mirror of official site: http://jasper-net.blogspot.com/

RSA Encryption with .NET 2.0 Cryptography Services and Crypto++ Wrapped as a Managed C++ Class Library

| Wednesday, April 7, 2010
Contents

   * Introduction
   * Disclaimer
   * Using the code
   * Glossary
   * Background
   * The Problem
         o Key Exchange
         o Data Transfer
         o Block Encryption and Decryption
   * Interop classes
         o CLR, Crypto++ and the C++ Standard Library
         o Setting pointers to the new and delete operators
   * Implementation Details
         o class RSAES_PKCS15 (Managed C++)
         o class CryptoPP_RSAES_PKCS15 (Native C++)
   * Tester Applications
         o C# Console Application Tester
   * Things to do
   * Other useful things
         o BER and DER encoding/decoding of Integers
   * Known Issues
         o LoaderLock Exception
         o Compiling Crypto++ as Unicode
         o Base64 Encoding/Decoding with Crypto++
   * In Closing
   * Acknowledgements
   * References
   * History

Introduction

The purpose of this article is to show the interaction between Crypto++ and .NET 2.0 Cryptography services using RSA PKCS#1 encryption and to show how to wrap a Crypto++ as a managed class. Often a client and server use different cryptographic services and need to interact correctly e.g. the public portions of the encryption key need to be exchanged between them and data from the client needs to be decrypted by the server and vice versa. Most of the articles I could find were for older versions of .NET and the documentation on how to use the Cryptography services was a bit sparse, hence the need for this article.

In order to simplify things, I have stripped away the usual communication links between the client and the server. Byte arrays will be passed between them instead. No existing standards will be used to exchange keys either, the public modulus and exponent integers will be sent as byte arrays again. Putting these components together is a plumbing job � explaining this would be very specific to my problem and would confuse a complicated article even more. Below is a short description of what will be achieved by this article:

I want to use Crypto++ from C#, so I wrap it using a managed C++ class as follows:

  1. Compile Crypto++ 5.5.1 either as a static lib or as a DLL using Visual Studio 2005 with dynamically linked standard multithreaded libraries (/MD or /MDd)
  2. Create a native wrapper class which provides a simple interface to Crypto++ and encrypts or decrypts a byte array of any size
  3. Create a managed C++ class which encapsulates the native wrapper class and converts .NET managed types to native types (and vice versa) and then calls the Crypto++ wrapper class methods


Read more: Codeproject

Posted via email from jasper22's posterous

0 comments: