Archive

Archive for the ‘Development’ Category

Encryption and decryption with X.509 certificates (with MIME Base64 Encoding)

March 29th, 2010 Logue 2 comments 626 views

We’ve been working on the last months with encyption and decryption using certificates for Biztalk, I haven’t found enough documentation out there but after some time we were able to encrypt and decrypt messages with a very little amount of code.

Messages are encrypted using a certificate’s public key, and decrypted using their private key. This way, to send a message to a particular recipient, he needs to have a certificate with a private key deployed on their side, and you need to have the certificate (only the public key is necessary) deployed on your side. No one will be able to decrypt the message without the private key (it’s an asymmetric encryption/decryption method).

We use this code to encrypt/decrypt messages inside Biztalk Server components, so the code we developed for encryption/decryption uses MIME Base64 Encoding, for example:

Content-ID: {F5BBE1D4-D0E3-4CD7-9B51-1129FA3077E1}
Content-Description: body
Bcc:
MIME-Version: 1.0
Content-type: application/x-pkcs7-mime; smime-type=enveloped-data; name="smime.p7m"
Content-Transfer-Encoding: base64

MIAGCSqGSIb3DQEHA6CAMIACAQAxgZEwgY4CAQAwODAkMSIwIAYDVQQDExlSQ0NMIEJpelRhbGsg
q49kxusLITM1r982n2MgZaa8vdgkLBLATSUWDEyDu/B57PZxxxU/AhEyIUppI5fsaxpI7NT+2QPW
8/HT7vfgH0t3ch3AUVglspS/NRYCuaOwG5lIpw9IAAAAAAAAAAAAAA==

How to use the Encrypt method

string messageToEncrypt = "message";
string certificateName = "MyCertificate";
string encryptedMessage = CryptographyHelper.Encrypt(messageToEncrypt, certificateName);

The certificate needs to be deployed on the Personal store inside your Local Machine (the code can be modified in the GetCertificate method to use another store).
To do this deployment, you may want to check this link: http://technet.microsoft.com/en-us/library/cc740068%28WS.10%29.aspx

How to use the Decrypt method

string decryptedMessage =  CryptographyHelper.Decrypt(messageToDecrypt);

This time, the certificate needs to be deployed at the same store but it’ll be necessary to deploy it including the private key. If the method throws an exception “the enveloped data-message does not contain the specified recipient”, this is because the certificate with the private key is not correctly deployed into the current account/local machine personal store.

Full source code and download for the CryptographyHelper ahead.
Read more…

Categories: Development Tags: , , ,

Tellago Devlabs on Codeplex

March 2nd, 2010 leandrodg No comments 123 views

At Tellago have opened a new codeplex workspace, the Tellago DevLabs.

We’ll be posting there all the open source projects we work on, we’ve already posted a second version of the Biztalk Data Services project, a RESTful API to manage and operate MS Biztalk Server 2009.

A couple of related posts by Tellago’s Chief Architect, Jesus Rodriguez:

Categories: Development Tags: ,

Service Configuration Editor with 64-Bit OS error: An extension of name ‘persistenceProvider’ already appears…

November 3rd, 2009 leandrodg No comments 522 views

I’m working on developing some WCF-Custom adapters for Biztalk 2009, so I needed to add some binding configuration to machine.config.

If you are trying to modify the computer WCF Configuration with the Service Configuration Editor to add a binding extension, behavior, binding element extension, etc., and you are working in a 64 bit environment, this error may occur:

An extension of name ‘persistenceProvider’ already appears in extension collection. Extension names must be unique. (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config (line 224)

If you open the configuration file (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config), you’ll probably find that it’s not repeated in that file. But it actually appears in another machine.config file.
Read more…

Biztalk Custom Functoid Wizard for Biztalk 2004 & 2006

June 29th, 2009 leandrodg 1 comment 2,602 views

First, this release got delayed about 3 years!. But, it still works fine and I’ve used it in many Biztalk Project over the last years, so I think it may be of use for every other BTS developer out there.

The idea behind this project is to be able to build custom Biztalk Functoids through a wizard. When this was built, there was not much information on the web about developing custom functoids, so it was a little hard to work on it. It’s based on Boudewijn van der Zwan and Scott Woodgate’s Biztalk Adapter Wizard. I’ve also based this development in Martijn Hoogendoorn’s Biztalk Pipeline Component Wizard. These are the original releases for this components: Adapter Wizard, Pipeline Wizard.

Basically a custom functoid is very similar to a Scripting Functoid with the same code copied once and again. The idea of developing a custom functoid instead of a Scripting Functoid is to avoid code repetition and to be able to modify it in every map that uses it simultaneously. This concept is known as DRY (Don’t repeat yourself).

I’ve built an original version for 2004 for an enormous project which required around 50 custom functoids to be built, of course building them by hand would be very time consuming. Adrian Lopez helped me adapt this version to Biztalk Server 2006, special thanks to him for the help!.

I’m posting both versions here, for Biztalk 2004 (and Visual Studio .NET 2003) and Biztalk 2006 (and Visual Studio .NET 2005).

Installation and usage is quite simple but I’ll show the usage step by step in a simple “Hello world” functoid sample.

Read more…

.NET C#: Recycle current Application Pool programmatically (for IIS 6+)

February 12th, 2008 leandrodg 6 comments 4,720 views

I’ve been working on how to recycle the current application pool for my ASP .NET application.

There are 3 steps for doing this:

  1. Verify if application is running on IIS that supports application pools (if not, there’s nothing to recycle).
  2. Get application pool name (obtained from the DirectoryServices entry corresponding to our virtual directory).
  3. Invoke Recycle method in the DirectoryServices entry corresponding to the application pool.

Read more…

Cassini & SerializationException: Type is not resolved for member…

December 18th, 2007 leandrodg 4 comments 2,872 views

I’m working on an architecture project now, and I needed to create an HttpModule which would measure the request time for pages.

So I needed to save information (the time and some other data) in the Begin_Request event and then read it in the End_Request event. I could have used Request.Context, but part of the idea of the project is this information in the current thread because it can be used both in Winforms and in Webforms.
This information is saved in the current thread using a class that implements ILogicalThreadAffinative. When I saved my information in the current thread (using CallContext.SetData()), suddenly an exception (not debuggeable) came up, which said:

System.Runtime.Serialization.SerializationException: Type is not resolved for member 'xxx'.
   at Microsoft.VisualStudio.WebHost.Server.GetProcessToken()
   at Microsoft.VisualStudio.WebHost.Host.GetProcessToken()
   at Microsoft.VisualStudio.WebHost.Request.GetUserToken()
   at Microsoft.VisualStudio.WebHost.Request.GetServerVariable(String name)
   at System.Web.Security.WindowsAuthenticationModule.OnEnter(Object source, EventArgs eventArgs)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Read more…

Categories: Development Tags: , , , ,

Performance Counter InstanceName issue

November 21st, 2007 leandrodg No comments 935 views

I was creating a performance counter collection to register the processing time for ASP.NET requests, and I decided the best way to name instances was to use Request.Url.Authority + Request.Url.PathAndQuery. This counters would allow me to check average response time, total requests and requests per second, for each Request.Url.Authority + Request.Url.PathAndQuery.

I built the counters and I decided to create a _total instance too, to sum up all the requests being made to the server.

Rarely, the _total instance worked like a charm when looking at it in PerfMon, but the other instances (for example, localhost/Test.aspx?query=x) didn’t show a value, they all showed “—” in the report view of PerfMon. I had no idea what the problem was, but I saw that the failing counters showed up in the counters list with localhost in the Parent column and Test.aspx?query=x in the Instance column.

Read more…

Determine current execution context (ASP.NET or Winforms)

October 5th, 2007 leandrodg 2 comments 2,154 views

I’ve searched over the internet for this and couldn’t find anything.

A method I’m working on should have a different behavior when called in a Web Application (Webforms) and a Windows Application (Winforms).

Read more…