Giter Club home page Giter Club logo

safestorage's Introduction

Safe Storage in .Net Core

Maybe You are Working On a Project ๐Ÿš€

Which Had Sensitive Datas ๐Ÿ’ข Like Connection Strings , Api Keys , Tokens(CSRF,JWT), Passwords , etc.

...

  • First Thing That is Important is Protection of These Datas on Every Existed Environment (Production,Staging,Development)
  • Second Thing That is How to Send/Receive it In Process of Deploy , Build , Run
  • Third and Most Important Thing is

    No Must Sensitive Data Particular ConnectionString in Source Code of Your Project ๐Ÿ˜ 

...

in .Net Core Exist Ways For Store Sensitive Datas in

DEVELOPMENT Environment :

  1. User Secrets
  2. Environment Variables
  3. Jwt Secret Manager

PRODUCTION Environment :

  1. CI/CD Principles
  2. Azure Key Vault
  3. Providers
  4. Docker , Kubertenes

STAGING Environment : is Used Only For Being Ready our App for Deploy on Production and Real World Processes

...

I Just Prevent Development Env

USER SECRETS

User Secret are Store Data in

%APPDATA%\Microsoft\UserSecrets\<user_secrets_id>\secrets.json

File System Path and On Linux (Like Kali or Ubuntu)

~/.microsoft/usersecrets/<user_secrets_id>/secrets.json

...

1.Create Simple WebApi Project (Create) :

dotnet new webapi --name SafeStorage -output <Path>

2.Enable User Secrets in Project (Initialize) :

dotnet user-secrets init

After That The UserSecretId Added To Yout csproj File

<UserSecretsId>2b61f88d-e83d-46f7-91da-faa5581c9d07</UserSecretsId>

3.Set Yout Secret (Set) :

dotnet user-secrets set "ConnectionString:MSSQL" "Data Source = localhost ...."

...

STORE AND SECRET DATA FROM JSON FILE LIKE appsettings.json

  1. Create and Enable Secrets Like Pervious Steps

  2. Store Data From appsettings.json :

     type ./appsettings.json | dotnet user-secrets set
     
     Successfully saved 3 secrets to the secret store.
    

...

HOW TO DELETE SETS ?

  1. Remove All :

     dotnet user-secrets clear
    
  2. Remove One :

     dotnet user-secrets remove "ConnectionStrings:MSSQL"
    

...

HOW TO USE THAT ?

1.In Program.cs :

var builder = WebApplication.CreateBuilder(args);
var movieApiKey = builder.Configuration["ConnectionStrings:MSSQL"];

var app = builder.Build();

app.MapGet("/", () => movieApiKey);

app.Run();

Configuration Automaticaly Read and Stores Datas From secrets.json and Return it

  1. Map to A Simple C# Class :

     public class ConfigurationSettings
     {
     public string MSSQLConnectionString { get; set; }
     }
    

    Now Bind Data To Class

     ConfigurationSettings mapClass = builder.Configuration.GetSection("ConnectionStrings:MSSQL").Get<ConfigurationSettings>()!;
    

Return it :

app.MapGet("/",()=> {
return ConnectionString;	
});
app.MapGet("/class",() => {
return mapClass;
});

Run Project :

dotnet run






Thank You ๐Ÿš€

safestorage's People

Contributors

moghaddm avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.