{"id":22839089,"url":"https://github.com/miqoas/miqo.encryptedjsonconfiguration","last_synced_at":"2025-05-08T02:46:18.884Z","repository":{"id":143378449,"uuid":"278095080","full_name":"miqoas/Miqo.EncryptedJsonConfiguration","owner":"miqoas","description":"Configuring your .NET Core with encrypted JSON files has never been so easy","archived":false,"fork":false,"pushed_at":"2024-09-03T21:00:23.000Z","size":111,"stargazers_count":34,"open_issues_count":2,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T20:45:00.903Z","etag":null,"topics":["aes-256","aes-gcm","configuration","dotnet","netcore31"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/miqoas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-08T13:21:02.000Z","updated_at":"2024-09-06T01:06:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"6b5bce0f-45ed-4925-b55c-e4ebcd15652b","html_url":"https://github.com/miqoas/Miqo.EncryptedJsonConfiguration","commit_stats":{"total_commits":10,"total_committers":1,"mean_commits":10.0,"dds":0.0,"last_synced_commit":"3d61a38e8536412e1a52213d7a7aecfa36d94ae2"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miqoas%2FMiqo.EncryptedJsonConfiguration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miqoas%2FMiqo.EncryptedJsonConfiguration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miqoas%2FMiqo.EncryptedJsonConfiguration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miqoas%2FMiqo.EncryptedJsonConfiguration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miqoas","download_url":"https://codeload.github.com/miqoas/Miqo.EncryptedJsonConfiguration/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252989941,"owners_count":21836665,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aes-256","aes-gcm","configuration","dotnet","netcore31"],"created_at":"2024-12-13T00:09:52.699Z","updated_at":"2025-05-08T02:46:18.864Z","avatar_url":"https://github.com/miqoas.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](.github/images/banner.png)\n\n### Configuring your .NET Core with encrypted JSON files has never been so easy\n\n![Build \u0026 Test](https://github.com/miqoas/Miqo.EncryptedJsonConfiguration/workflows/Build%20\u0026%20Test/badge.svg)\n\nUse encrypted JSON file with this configuration provider for .NET Core's `Microsoft.Extensions.Configuration`. The JSON files use AEAD AES-256-GCM encryption.\n\n### Motivation\n\nProjects often contains sensitive information like database connection strings, API keys or usernames and passwords for external services. This information should never be committed to source control and should be handled in a secure way. Key vaults like those provided by Azure and AWS aren't always available for projects that can't be connected to the internet.\n\n## Installation\n\nYou can install the package via the NuGet Package Manager by searching for `Miqo.EncryptedJsonConfiguration`. You can also install the package via PowerShell using the following command:\n\n```ps\nInstall-Package Miqo.EncryptedJsonConfiguration\n```\n\nor via the dotnet CLI:\n\n```ps\ndotnet add package Miqo.EncryptedJsonConfiguration\n```\n\n## Getting started\n\nAdd the following to your `Program.cs` file:\n\n```csharp\nusing Miqo.EncryptedJsonConfiguration;\n```\n\nTo decrypt a configuration file you will need a base64 formatted encryption key:\n\n```csharp\nvar key = Convert.FromBase64String(Environment.GetEnvironmentVariable(\"SECRET_SAUCE\"));\n```\n\n### Loading the encrypted JSON configuration\n\nThe encrypted JSON configuration can be loaded from a file in your `Program.cs` like this:\n\n```csharp\nHost.CreateDefaultBuilder(args)\n    .ConfigureAppConfiguration((hostingContext, config) =\u003e\n    {\n        config.AddEncryptedJsonFile(\"settings.ejson\", key);\n    })\n    ...\n```\n\n`AddEncryptedJsonFile()` also supports the `optional` and `reloadOnChange` parameters.\n\nYou can also load the encrypted JSON configuration from a stream like this:\n\n```csharp\nHost.CreateDefaultBuilder(args)\n    .ConfigureAppConfiguration((hostingContext, config) =\u003e\n    {\n        config.AddEncryptedJsonStream(ejsonStream, key);\n    })\n    ...\n```\n\nYou can now access your application's settings by injecting `IConfiguration` or `IOptions` in your classes.\n\n### Accessing the configuration from your code\n\nYou can load your configuration into your own custom settings class. Create a class with the properties that matches your encrypted JSON file:\n\n```csharp\npublic class AppSettings\n{\n    public string ConnectionString { get; set; }\n    public string EmailApiKey { get; set; }\n}\n```\n\nAdd the following to `ConfigureServices` method in your  `Startup.cs` file:\n\n```csharp\nservices.AddJsonEncryptedSettings\u003cAppSettings\u003e(_configuration);\n```\n\nYour configuration will be loaded into your AppSettings class object and can be injectedable singleton in your code.\n\n```csharp\nprivate readonly AppSettings _settings;\n\npublic YourController(AppSettings settings)\n{\n    _settings = settings;\n}\n\npublic void GetRecordsFromDatabase()\n{\n    var connectionString = _settings.ConnectionString;\n}\n```\n\n## Creating an encrypted configuration file\n\nThe easiest way to create encrypted configuration files and encryption keys is to use the [Kizuna](https://github.com/miqoas/Kizuna) command line tool. Please check the tool's GitHub page for more information.\n\nYou can still encrypt the configuration files from your own code if you prefer that.\n\n### Using Kizuna\n\nBefore you begin you need to install the Kizuna command line tool. See the [Kizuna project page](https://github.com/miqoas/Kizuna).\n\nStart by creating a new encryption key.\n\n```bash\n$ kizuna generate\n```\n\nMake sure you write down the encryption key in a safe location, like a password manager (1Password, LastPass, etc.). Never commit the encryption key into source code.\n\nCreate a JSON file in your favorite file editor. When you are ready to encrypt the JSON file, use the following command.\n\n```bash\n$ kizuna encrypt -k {key} {filename}\n```\n\nIf you need to decrypt the file to make changes you can use the following command:\n\n```bash\n$ kizuna decrypt -k {key} {filename}\n```\n\nThe file's contents is replaced with the encrypted or decrypted configuration when the `encrypt` or `decrypt` command is used. Add the `-c` option to output to your console instead of writing to the file system.\n\n### Encrypting the configuration file yourself\n\nIf you prefer to create your JSON configuration files programatically then you'll find some helpful helper methods in the static `AesEncryptionHelpers` class.\n\nGenerate an encryption key:\n\n```csharp\nvar key = AesEncryptionHelpers.GenerateBase64EncodedKey();\n```\n\nTo serialize a settings class and encrypt it:\n\n```csharp\nvar cipher = AesEncryptionHelpers.Encrypt\u003cAppSettings\u003e(settings, key);\n```\n\nThe `AesEncryptionHelpers` static class also include methods these methods to help you generate encryption keys, encrypt or decrypt text:\n\n* `byte[] GenerateKey()`\n* `string GenerateBase64EncodedKey()`\n* `string Encrypt(string text, string key)`\n* `string Encrypt(byte[] text, byte[] key)`\n* `string Encrypt\u003cT\u003e(T settings, string key)`\n* `string Encrypt\u003cT\u003e(T settings, byte[] key)`\n* `string Decrypt(string cipher, string key)`\n* `string Decrypt(byte[] cipher, byte[] key)`\n\n## Acknowledgements\n\nMiqo.EncryptedJsonConfiguration uses some of the encryption code from the [CryptHash.NET](https://github.com/alecgn/crypthash-net/) (MIT license) library for it's AES-256-GCM operations.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiqoas%2Fmiqo.encryptedjsonconfiguration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiqoas%2Fmiqo.encryptedjsonconfiguration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiqoas%2Fmiqo.encryptedjsonconfiguration/lists"}