This is a class.
Public static class encryptionconfig {/* encryption configuration node * response. write (encryptionconfig. encryption ("connectionstrings"); * decrypts the configuration node * response. write (encryptionconfig. deciphering ("connectionstrings"); * reading response is not affected. write (webconfigurationmanager. appsettings [0]. tostring (); response. write (webconfigurationmanager. appsettings [1]. tostring (); * // <summary> // encrypt the configuration node /// </Summary> /// <Param name = "STRs Ection "> </param> // <returns> </returns> Public static string encryption (string strsection) {system. configuration. configuration Config = webconfigurationmanager. openwebconfiguration (system. web. httpcontext. current. request. applicationpath); // find the specified section system in the opened configuration file. configuration. configurationsection section = config. getsection (strsection); If (section! = NULL &&! Section. sectioninformation. isprotected) {Section. sectioninformation. protectsection ("rsaprotectedconfigurationprovider"); config. save (); Return "encryption successful" ;}else {return "encryption failed ";}} /// <summary> /// decrypt the configuration node /// </Summary> /// <Param name = "strsection"> </param> /// <returns> </returns> Public static string deciphering (string strsection) {system. configuration. configuration Config = webconfigurationmanag Er. openwebconfiguration (system. Web. httpcontext. Current. Request. applicationpath); system. configuration. configurationsection section = config. getsection (strsection); If (section! = NULL & section. sectioninformation. isprotected) {Section. sectioninformation. unprotectsection (); config. save (); Return "decryption successful" ;}else {return "decryption failed ";}}}