20 May 2014

Hafiz Adewuyi

ENCRYPT OR DECRYPT ‘hibernate-configuration’ section of an ASP.NET application configuration file


(1) Copy NHibernate.dll to the location of .NET framework

  • Open the location of the website on the file system, e.g. C:\inetpub\wwwroot\MyWebsite;
  • Open the bin folder (\bin);
  • From \bin, copy Nhibernate.dll to the location of Microsoft .NET framework. If you are using .NET framework 4.0, this location is likely to be: C:\Windows\Microsoft.NET\Framework\v4.0.30319;

Though, highly unlikely, if you happen not to find NHibernate.dll in your website /bin folder, you can get the dll from any other source.

This step is highly important. If skipped, command prompt will complain about not being able to find NHibernate.dll when you run the command. As a result, the encryption attempt will fail.

(2) Run command prompt (cmd.exe) as administrator

(3) Navigate to the location of Microsoft .NET framework using the command like so:

cd C:\Windows\Microsoft.NET\Framework\v4.0.30319

(4) Run the encryption command

Command: aspnet_regiis -pe "hibernate-configuration" -app "/WebsiteNameOnIIS"

Note that the highlighted section (WebsiteNameOnIIS) must be replaced with the name of the application as deployed on IIS. E.g. for an application deployed as MyWebsite on IIS, you will have:
aspnet_regiis -pe "hibernate-configuration" -app "/ MyWebsite"

You should get a Succeeded! message is the process was successful. If it fails, verify that the name of the application on IIS is correct and retry. Also, verify that you ran cmd.exe as administrator.

(5) Confirm encryption

Open the target configuration file and inspect hibernate-configuration section to confirm encryption.


(1) Follow the same steps for encryption, except for step 4 where the command should be replaced with this:

Command: aspnet_regiis -pd "hibernate-configuration" -app "/WebsiteNameOnIIS"

* Note that the only change is that –pe is now –pd (e for encrypt, d for decrypt, I guess).

Subscribe to this Blog via Email :