Ways around putting a password in code

后端 未结 3 595
梦毁少年i
梦毁少年i 2020-12-31 18:16

I have a bit of code that needs to run with elevated privileges (more that I want the rest of my code running at).

I have my code that sets up the Impersonation work

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 18:51

    You can use safe-config nuget package. Internally it uses data protection api to encrypt and decrypt data.

    //Save some configuration data at folder data\temp\
    var configManager = new ConfigManager()
        .WithOptions(DataProtectionScope.CurrentUser)
        .Set("password", "my-massword")
        .AtFolder(@"data\temp\")
        .Save();
    
        ...
    
    //Load configuration data
    var loadedValue = new ConfigManager()
        .AtFolder(@"data\temp\")
        .Load()
        .Get("password");
    

提交回复
热议问题