{"id":252,"date":"2020-08-03T21:20:21","date_gmt":"2020-08-03T19:20:21","guid":{"rendered":"http:\/\/archicode.azurewebsites.net\/?p=252"},"modified":"2020-08-03T21:20:21","modified_gmt":"2020-08-03T19:20:21","slug":"safely-store-secrets-during-development","status":"publish","type":"post","link":"https:\/\/archicode.be\/index.php\/2020\/08\/03\/safely-store-secrets-during-development\/","title":{"rendered":"Safely store secrets during development"},"content":{"rendered":"\n<p>When developing an application, we sometimes need to call an api or connect to a database and for this, we use passwords or keys to connect.  If we put them in the appsettings, there&#8217;s always the danger of forgetting about them and commit them to source control which can then cause a security flaw.<\/p>\n\n\n\n<p>To prevent this, dotnet provides us with a very useful command to safely store our secrets where they won&#8217;t be accidentally committed.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>First open a command line in your solution folder<\/li><li>Execute this command : <br><code>dotnet user-secrets init<\/code><br>This command initialises the local secret repository of your solution<\/li><li>To store data, use this command<br><code>dotnet user-secrets set \"keyname\" \"keyvalue\"<\/code><\/li><\/ol>\n\n\n\n<p>Now we can easily access it from our Console application without risking this secret to leak or end up in the wrong hands.  <\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>You need to install the following nuget Packages into your solution <br><code>Microsoft.Extension.Configuration<\/code><br><code>Microsoft.Extension.Configuration.UserSecrets<\/code><\/li><li>In your Program.cs file you will need a ConfigurationBuilder and tie the Id you received from the init command you ran before to the builder<br><code>var builder = new ConfigurationBuilder();<br>builder.AddUserSecrets(\"511ae28b-c9d3-4e21-979f-a310df6102ad\");<\/code><\/li><li>After a call to the buillder.Build() method you can now access your secret<br><code>var configuration = builder.Build();<\/code><br><code>var secret = configuration[\"Secret\"];<\/code><br><\/li><\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">Happy coding<\/h4>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When developing an application, we sometimes need to call an api or connect to a database and for this, we use passwords or keys to connect. If we put them in the appsettings, there&#8217;s always the danger of forgetting about them and commit them to source control which can then cause a security flaw. To&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[2],"tags":[15,16,26],"class_list":["post-252","post","type-post","status-publish","format-standard","hentry","category-net","tag-configuration","tag-dotnet","tag-secret"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":159,"url":"https:\/\/archicode.be\/index.php\/2020\/06\/24\/feature-flags-using-azure-feature\/","url_meta":{"origin":252,"position":0},"title":"Feature flags using Azure feature","author":"Hakim","date":"June 24, 2020","format":false,"excerpt":"Feature flags are very useful when you develop an application and while you don't want users to use the feature that isn't really ready, you don't want to stay on a side branch for too long as merging and rebasing from the main branch can become quite the chore. Enter\u2026","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/archicode.be\/index.php\/category\/net\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":92,"url":"https:\/\/archicode.be\/index.php\/2019\/06\/10\/how-to-blazorify-an-existing-mvc-app\/","url_meta":{"origin":252,"position":1},"title":"How to blazorify an existing mvc app","author":"Hakim","date":"June 10, 2019","format":false,"excerpt":"Blazor is awesome. \u00a0If you don't know what it is, you can check it out here\u00a0but to summarize, it's a framework that allows .net code to run in your browser using the power of Web Assembly. I've found a lot of tutorials using the official blazor templates but only hints\u2026","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/archicode.be\/index.php\/category\/net\/"},"img":{"alt_text":"migrate_solution_to_dotnet_core_3.gif","src":"\/wp-content\/uploads\/2019\/06\/migrate_solution_to_dotnet_core_3.gif","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2019\/06\/migrate_solution_to_dotnet_core_3.gif 1x, \/wp-content\/uploads\/2019\/06\/migrate_solution_to_dotnet_core_3.gif 1.5x, \/wp-content\/uploads\/2019\/06\/migrate_solution_to_dotnet_core_3.gif 2x, \/wp-content\/uploads\/2019\/06\/migrate_solution_to_dotnet_core_3.gif 3x, \/wp-content\/uploads\/2019\/06\/migrate_solution_to_dotnet_core_3.gif 4x"},"classes":[]},{"id":302,"url":"https:\/\/archicode.be\/index.php\/2023\/10\/31\/migrating-an-old-net-app-using-unsupported-tech-a-step-by-step-guide\/","url_meta":{"origin":252,"position":2},"title":"Migrating an Old .NET App Using Unsupported Tech: A Step-by-Step Guide","author":"Hakim","date":"October 31, 2023","format":false,"excerpt":"In today's rapidly evolving tech landscape, it's quite common to find yourself in a situation where you need to migrate an old .NET app that relies on unsupported technologies. While this can be a daunting task, with careful planning and implementation, it's possible to breathe new life into your application.\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/archicode.be\/wp-content\/uploads\/2023\/10\/7c746f75-2548-471c-891a-05bfaa537995.jpeg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/archicode.be\/wp-content\/uploads\/2023\/10\/7c746f75-2548-471c-891a-05bfaa537995.jpeg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/archicode.be\/wp-content\/uploads\/2023\/10\/7c746f75-2548-471c-891a-05bfaa537995.jpeg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/archicode.be\/wp-content\/uploads\/2023\/10\/7c746f75-2548-471c-891a-05bfaa537995.jpeg?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":370,"url":"https:\/\/archicode.be\/index.php\/2024\/05\/14\/understanding-blazor-component-parameters\/","url_meta":{"origin":252,"position":3},"title":"Understanding Blazor Component Parameters","author":"Hakim","date":"May 14, 2024","format":false,"excerpt":"Understanding Parameters Parameters in Blazor are used to pass data from a parent component to a child component. They are defined using public properties on a component and decorated with the [Parameter] attribute. Non-Complex Objects Non-complex objects such as integers, strings, and booleans can be passed as parameters. Here\u2019s an\u2026","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/archicode.be\/index.php\/category\/net\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":377,"url":"https:\/\/archicode.be\/index.php\/2024\/05\/15\/issue-when-debugging-azure-function-locally\/","url_meta":{"origin":252,"position":4},"title":"Issue when debugging Azure Function locally","author":"Hakim","date":"May 15, 2024","format":false,"excerpt":"If you're developing Azure Functions, it may happen that you encounter this error : Failed to decrypt settings. Encrypted settings only be edited through 'func settings add'. That often means that there's an issue with your local.settings.json file. There are different ways that people might use to circumvent this error\u2026","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/archicode.be\/index.php\/category\/net\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":20,"url":"https:\/\/archicode.be\/index.php\/2019\/02\/16\/esp8266-the-iot-prototyping-graal\/","url_meta":{"origin":252,"position":5},"title":"Esp8266 &#8211; the IOT prototyping Graal","author":"Hakim","date":"February 16, 2019","format":false,"excerpt":"1. A Esp-01 (the most basic of all the Esp8266) I've been working for some time now with IOT and I've worked extensively with the Esp8266 chip just because I'm testing a lot of stuff and don't want to spend a lot of money in it. You can get these\u2026","rel":"","context":"In &quot;IoT&quot;","block_context":{"text":"IoT","link":"https:\/\/archicode.be\/index.php\/category\/iot\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/posts\/252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/comments?post=252"}],"version-history":[{"count":0,"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/posts\/252\/revisions"}],"wp:attachment":[{"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/media?parent=252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/categories?post=252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/tags?post=252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}