How to Decrypt a K2Hostserver.config file in Order to Add a New Connection String
In order to keep connection strings secure within the K2 config files, the K2 host server (K2HostServer.exe) will encrypt any plain text connections strings it finds when it starts up. While this does prevent it from being human readable, it also makes it difficult if you need to manually change one of the parameters in the connection string, or add a new connection string for use within a custom K2 component.
I recently needed to add a custom connection string to the K2 server config file. After a bit of research and trial and error I was able to figure out how to use the .NET Framework aspnet_regiis utility to decrypt the K2 server config file. Once decrypted, I then added the connection string. The K2 server will then automatically encrypt it the next time it starts up.
Below are the steps I performed. If anyone knows a better way, please share. The below steps could easily be put into a batch file to make it more repeatable.
1. Create a new directory on the local sever (in this example C:\Temp\K2Config was created)
2. Create a backup copy of the K2 config file ‘C:\Program Files\K2 blackpearl\Host Server\Bin\K2HostServer.config’ for safe keeping
3. Copy the file ‘C:\Program Files\K2 blackpearl\Host Server\Bin\K2HostServer.config’ to this new directory
4. In this new directory, rename the ‘K2HostServer.config’ to ‘web.config’
5. Open the Windows command prompt
6. Change Directory in the command prompt to ‘C:\Program Files\K2 blackpearl\Host Server\Bin\K2HostServer.config’
7. Run the following command:
aspnet_regiis -pdf "connectionStrings" "C:\Temp\K2Config"
8. You should see:

9. Rename the web.config file to ‘K2HostServer.config’
10. Edit this K2HostServer.config file and add a new connection string
11. Save the config file.
12. Copy this file back to the original location (‘C:\Program Files\K2 blackpearl\Host Server\Bin’)
13. Restart the K2 service
14. The K2 service should encrypt it upon service restart.