Google
 

4.26.2006

HexToBin and BinToHex

While dealing with storing parts of an X509 certificate, I’ve found the need for a couple of utility methods that allow converting the string representations of the Public Key to a byte array (or vice versa). That’s what the HexToBin() method does. Included also is BinToHex() for going the other direction.


If you found this article helpful:

4.19.2006

New BETA2 of Microsoft Threat Analysis & Modeling v2.0

BETA2 of Microsoft Threat Analysis & Modeling v2.0 (formerly codenamed “ACE Torpedo”) is now available for download here.

This tool is really starting to shape up!

4.03.2006

HOWTO: Use the aspnet_setreg utility to encrypt other values in the Web.Config

Here’s a slight hack I came up with to store encrypted connection strings in the registry that mimic the aspnet_setreg utility that comes with the .NET framework:

First you’ll run the aspnet_setreg command:

c:\> aspnet_setreg -k:Software\ASP.NET\MyKey -c:"data source=server;userid=user;password=password"

Please edit your configuration to contain the following:

sqlConnectionString = "registry:HKLM\Software\ASP.NET\MyKey\ASPNET_SETREG,sqlConnectionString"

The DACL on the registry key grants Full Control to System, Administrators, and Creator Owner.

If you have encrypted credentials for the <identity> configuration section, or a connection string for the <sessionstate> configuration section, ensure that the process identity hasRead access to the registry key. Furthermore, if you have configured IIS to access content on a UNC share, the account used to access the share will need Read access to the registry key. Regedt32.exe may be used to view/modify registry key permissions.

You may rename the registry subkey and registry value in order to prevent discovery.This command will create a Key in the registry here:

HKEY_LOCAL_MACHINE\Software\ASP.NET\MyKey\ASPNET_SETREG

Within that key it will create a Binary Value called “sqlConnectionString” set to the encrypted value of your connection string.

From here, I like to make one more modification:

Since I may not be storing a SQL Connection string, I’ll rename "sqlConnectionString" to something else more meaningful. For this example I’ll rename it to "customConnectionString"Next, I’ll add the following to my ‘web.config’

Next, I have written the following class which takes advantage of the NCrypto library to easily decrypt the connection string in the registry.

Finally, all that is left is to use the code above to extract the encrypted value from the connection string whenever you need it:



That's all there is to it.
References: How to use the ASP.NET utility to encrypt credentials and session state connection strings (Microsoft KB329290)

If you find this article helpful: kick it on DotNetKicks.com