How to store user setting and passwords in add-in

I’m currently building a SolidWorks add-in in C# targeting .NET Framework. Beside the class library project of the add-in, I have a class library to handle a connection to SQL database.

Now I wonder how to store the connection string to the database (and eventually others information). Ideally I would like to:

  1. not have it in the source control (I’m using Git)
  2. not have it readily available to the end user

I though of storing the data in a json file that I can add to the .gitignore file, but the second point would not be solved.

I read that .NET can store secrets, but I don’t know that if it’s true for .NET Framework. I also though of using an API as a middle layer between the add-in and the database, to handle the authentication, but I’m not a programmer and it will add to much complexity.

How would you solve the issue? Is there a solution?

Thanks in advance.

Would it be possible to set this at runtime and either store it in appdata or the registry?

I think so, but if I set it at run time I would need to hard code the value in the code, but I don't want to have them in source control. Am I missing something about your comment?

3 Answers

3

1.You can simply encrypt the JSON string and store it in any custom file located in the plugin’s installation path, such as a .db, .ini, or registry file.
2.As for how to encrypt the string, you can use chatgpt.

Thanks for the answer, I think I will look into that. Would you store the key to encript/decript the file in the code?

If there is a key in your code, you need to obfuscate the code in your generated DLL. There are tools available on GitHub for this. However, if you really want to keep it confidential, it's best to create a web API to perform decryption on a remote server. (If you don't mind, you can just include it in the code, but this won't prevent decompilation).

app.config is a good option

HI! I'm a bit of a noob: is app.config an option in a class library?

image

Yes it is an option in a class library