Thursday, May 23, 2013

C++/CLI library in BizTalk component

For a BizTalk project I needed to decrypt a password stored in a database that was encrypted using a legacy unmanaged C++ Blowfish static library. In attempting to write a C# blowfish decrypter, it was discovered that the Blowfish library wasn't really a 'true' implementation of Blowfish. Since redoing the encryption was not an option due to many factors, I decided to write a managed C++/CLI wrapper class of the static libraries. Using this as a guide (http://tom-shelton.net/?p=95), I went about creating the wrapper class. Most of the challenges of getting the wrapper class to work revolved around matching data structures between the managed and unmanaged code. Special care should be taken to clean up any unmanaged objects.

A pipeline component was created that made the database lookup, decrypted the password using the wrapper class and inserted the password into the outgoing message. To use the wrapper dll, it needed to be strong named. I'm sure there is probably a way to do that in a post-build command, but I did it manually using
 sn -Rca //pathtodll keycontainer  
The dll needs to be gaced into the 32 bit Global Assembly Cache. Any BizTalk host that uses the pipeline component should be checked 32-bit only.

No comments: