Cross-Platform Sensitive Data Storage for .NET Applications on Debian, macOS, and Windows

Konstantinos Kanellakis 0 Reputation points
2024-03-12T07:31:35.5433333+00:00

How can I securely store sensitive information such as tokens and keys for my .NET application in the operating system? While Credential Manager is a great option for Windows, I'm having trouble finding a code solution that works with keyring on Linux.

I tried using libsecret-1 and gnome-keyring but I found it hard to set up and have it automatically run/start when the user logs in. It relies to gui to login to keyring but I want support for distros with no gui. Tested this project.

Something I could utilize was pass which was easy to setup and use in terminal but couldnt find a library to manipulate it through code.

I have not make any search for macOS, but I think keyring is an option also(?).

Is there any better solution? The app uses SQLite which I dont know if it is possible to be encrypted or how secure the encryption is.

My application is developed using v4.7.1 of .NET.

Developer technologies .NET Other
Developer technologies C#
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. hossein jalilian 10,825 Reputation points Volunteer Moderator
    2024-03-15T07:22:05.5266667+00:00

    Thanks for posting your question in the Microsoft Q&A forum.

    I suggest storing this data in the database in a hashed format and loading it into memory when the application starts up for faster access. For updating the information, you can implement a handler to detect changes in the database and update the corresponding data in memory accordingly.

    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful


  2. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2024-03-15T21:54:16.1933333+00:00

    on linux most of the keyring apps are written in python. you might do better executing the cli. while not done on windows, unix was designed to call executables and it is fast. granted the .net code for this is more complex than the unix code

    FILE *fp;      /* command output stream */
    char *command; /* command contains the command string (a character array) */
    /* If you want to read output from command */
    fp = popen(command,"r"); 
       /* read output from command */
       fscanf(fp,....);   /* or other STDIO input functions */
         
    fclose(fp);
    

    on MacOs and IOS you use the KeyChain to store secrets.

    import KeychainAccess
    
    let keychain = Keychain(service: "com.example.myapp")
    try keychain.set("secret data", key: "secret_data")
    
    let value = try keychain.get("secret_data")
    print(value)
    

    android has a Keystore system.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.