.net - How to safely store API credentials in a C# file shared on GitHub? -


i'm making client app windows 10. have problem i'd open-source code, leave api key invisible other people. relevant portion of source file:

private const string apikey = "your_api_key"; 

i'd have transformed to

private const string apikey = "the_actual_api_key"; 

when compiled. how go doing this?


edit: sorry ambiguities; asking how prevent viewers of source code on github seeing string, whilst not having change during local builds. question not relate encryption in way.

here's how ended solving problem.

i added class project called credentials.cs:

public static class credentials {     public const string apikey = "your_api_key"; } 

all further references api key made via field added. example:

public void makerequest() {     var client = new apiclient(credentials.apikey);     client.dosomething(); } 

now magical part. after committing file via git, ran git update-index --assume-unchanged credentials.cs, (as per this answer) tells git stop tracking changes file. in other words, if modify file , run git diff or git status, nothing show up.

then replaced your_api_key actual api key in file, , works perfectly.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -