Thursday, 23 May 2013

GNUPG Encoder - Biztalk custom pipeline component



This Article helps in creating Custom pipeline component for PGP encryption using GNUPG software.

Download and install GNUPG on machine.

Generate keys for Encryption using command 






























gpg --gen-key


Receipientid : Test@company.com

Passphase : Test@123

Remember Email Id and Passphase as these are required during encryption.

Code For creating Pipeline component is : 


public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(IPipelineContext pContext, Microsoft.BizTalk.Message.Interop.IBaseMessage pInMsg)
        {
            IBaseMessage outMsg = pInMsg;
            msgPart = pInMsg.BodyPart;
            Stream originalStream = pInMsg.BodyPart.GetOriginalDataStream();
            try
            {
                if (msgPart != null)
                {
                    if (originalStream != null)
                    {
                        byte[] arrByte = new byte[0];
                        originalStream = (new MemoryStream(arrByte));

                        // Code Added Here
                        GnuPG gpg = new GnuPG();
                        gpg.BinaryPath = Path.GetDirectoryName(textAppPath);
                        gpg.Recipient = textReceipientId;
                        //  Perform encryption

                        // convert string to stream
                        MemoryStream encryptedStream = new MemoryStream();
                        gpg.Encrypt(originalStream, encryptedStream);
                        encryptedStream.Seek(0, SeekOrigin.Begin);
                        msgPart.Data = encryptedStream;
                        outMsg = pInMsg;
                        outMsg.BodyPart.Data = encryptedStream;
                        //
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return outMsg;
        }

After creating pipeline component , you need to install dll in GAC and copy dll at location 

“C:\Program Files\Microsoft BizTalk Server 2010\Pipeline Components”..

Now creates send pipeline and add this component at encode stage.






















Deploy and configure solution using admin console.
 












Download sorce code from MSDN.

1 comment:

  1. AWS is a complete secure cloud stage which offers more than 175 completely highlighted administrations. It was intended to help all organizations, from little new companies to huge ventures, to turn out to be more adaptable and to advance all the more productively at low expenses. With AWS organizations can moderately send off servers basically, have static sites and email servers or store information, relocate their current data sets to the cloud, make s1erverless capabilities to screen assets and that's only the tip of the iceberg>> aws cloud expert

    ReplyDelete