{"id":7747,"date":"2013-06-12T11:33:29","date_gmt":"2013-06-12T16:33:29","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=7747"},"modified":"2014-10-09T11:09:35","modified_gmt":"2014-10-09T16:09:35","slug":"encrypt-asp-net-configuration-in-web-config-using-aspnet_regiis-exe","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=7747","title":{"rendered":"Encrypt ASP.NET Configuration in Web.config Using aspnet_regiis.exe"},"content":{"rendered":"<div class='toc wptoc'>\n<h2>Contents<\/h2>\n<ol class='toc-odd level-1'>\n\t<li>\n\t\t<a href=\"#Prerequisites\">Prerequisites<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#Note\">Note<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#Examples\">Examples<\/a>\n\t\t<ol class='toc-even level-2'>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Encrypt_appSettings_section\">Encrypt <em>appSettings<\/em> section<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Decrypt_appSettings_section_for_Editing\">Decrypt <em>appSettings<\/em> section for Editing<\/a>\n\t\t\t<\/li>\n\t\t<\/ol>\n\t<li>\n\t\t<a href=\"#EncryptDecrypt_C_Application_Config_Section\">Encrypt\/Decrypt C# Application Config Section<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#References\">References<\/a>\n\t<\/li>\n<\/ol>\n<\/ol>\n<\/div>\n<div class='wptoc-end'>&nbsp;<\/div>\n<span id=\"Prerequisites\"><h2>Prerequisites<\/h2><\/span>\n<p>* Windows Server 2008 R2<br \/>\n* Run the commands from <strong>same<\/strong> directory as <em>web.config<\/em>:<\/p>\n<span id=\"Note\"><h2>Note<\/h2><\/span>\n<p>* No need to decrypt in application code. The encrypted section will be automatically decrypted during runtime.<\/p>\n<span id=\"Examples\"><h2>Examples<\/h2><\/span>\n<span id=\"Encrypt_appSettings_section\"><h3>Encrypt <em>appSettings<\/em> section<\/h3><\/span>\n<p>* Encrypt the whole <em>appSettings<\/em> section in <em>web.config<\/em> file.<\/p>\n<pre lang=\"bat\">\r\nC:\\Windows\\Microsoft.NET\\Framework64\\v2.0.50727\\aspnet_regiis.exe -pef appSettings . -prov DataProtectionConfigurationProvider\r\n<\/pre>\n<p>* After encryption:<\/p>\n<pre lang=\"xml\">\r\n<configuration>\r\n<appSettings configProtectionProvider=\"DataProtectionConfigurationProvider\">\r\n  <EncryptedData>\r\n   <CipherData>\r\n    <CipherValue>...<\/CipherValue>\r\n   <\/CipherData>\r\n  <\/EncryptedData>\r\n<\/appSettings>\r\n..\r\n<\/configuration>\r\n<\/pre>\n<span id=\"Decrypt_appSettings_section_for_Editing\"><h3>Decrypt <em>appSettings<\/em> section for Editing<\/h3><\/span>\n<pre lang=\"bat\">\r\nC:\\Windows\\Microsoft.NET\\Framework64\\v2.0.50727\\aspnet_regiis.exe -pdf appSettings .\r\n<\/pre>\n<span id=\"EncryptDecrypt_C_Application_Config_Section\"><h2>Encrypt\/Decrypt C# Application Config Section<\/h2><\/span>\n<p>* Same approach can be used to encrypt\/decrypt C# application config files.<br \/>\n* Follow the steps:<br \/>\n&#8211; Rename application config file to <strong>web.config<\/strong><br \/>\n&#8211; Run encrypt\/decrypt command<br \/>\n&#8211; Rename <em>web.config<\/em> back to application config file name<\/p>\n<span id=\"References\"><h2>References<\/h2><\/span>\n<p>* <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/k6h9cz8h%28v=vs.80%29.aspx\">ASP.NET IIS Registration Tool (Aspnet_regiis.exe)<\/a><br \/>\n* <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/zhhddkxy%28v=vs.100%29.aspx\">Encrypting and Decrypting Configuration Sections<\/a>  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prerequisites * Windows Server 2008 R2 * Run the commands from same directory as web.config: Note * No need to decrypt in application code. The encrypted section will be automatically decrypted during runtime. Examples Encrypt appSettings section * Encrypt the &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=7747\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[6],"tags":[383,382,359,381],"class_list":["post-7747","post","type-post","status-publish","format-standard","hentry","category-iis","tag-decrypt","tag-encrypt","tag-iis-2","tag-web-config"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-20X","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/7747","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7747"}],"version-history":[{"count":5,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/7747\/revisions"}],"predecessor-version":[{"id":7749,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/7747\/revisions\/7749"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}