You can encrypt your web.config in two ways. Either using codebehind or command line as described this article encrypting web.config file
According to the above resource, when you encrypt your web.config file using command line, then you have to export the required files to your web server in order for your application to encrypt and decrypt the web.config file successfully.
But using codebehind makes things easier cos there is no exportation of keys here. Everything can be performed on your web server with just a click.
Mine was done in VB.Net so the above link was really helpful. As per your case, you may try converting the code using code converter.