Kapela.Security.Encryption.Net4 4.0.2

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Kapela.Security.Encryption.Net4 --version 4.0.2
                    
NuGet\Install-Package Kapela.Security.Encryption.Net4 -Version 4.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Kapela.Security.Encryption.Net4" Version="4.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kapela.Security.Encryption.Net4" Version="4.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Kapela.Security.Encryption.Net4" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Kapela.Security.Encryption.Net4 --version 4.0.2
                    
#r "nuget: Kapela.Security.Encryption.Net4, 4.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Kapela.Security.Encryption.Net4@4.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Kapela.Security.Encryption.Net4&version=4.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Kapela.Security.Encryption.Net4&version=4.0.2
                    
Install as a Cake Tool

🔐 Kapela.Security.Encryption.Net4

ProtĂ©gez les donnĂ©es sensibles de votre application .NET Framework — mots de passe, chaĂźnes de connexion, clĂ©s d'API — en les chiffrant directement dans votre configuration.

⚠ Ce package cible .NET Framework 4.8 / 4.8.1. Pour les applications .NET, prĂ©fĂ©rez Kapela.Security.Encryption.


📩 Installation

Install-Package Kapela.Security.Encryption.Net4

đŸ—ïž ClĂ© de chiffrement

La clĂ© peut ĂȘtre initialisĂ©e au dĂ©marrage, sinon elle est gĂ©nĂ©rĂ©e automatiquement :

// À appeler au dĂ©marrage de l'application, avant tout chiffrement ou dĂ©chiffrement
EncryptionHelper.SetEncryptionKey("NomDeMonApplication");

⚠ Les valeurs chiffrĂ©es avec une clĂ© ne peuvent ĂȘtre dĂ©chiffrĂ©es qu'avec cette mĂȘme clĂ©.


✏ Chiffrement et dĂ©chiffrement

Opérations de base sur une valeur :

using Kapela.Security.Encryption.Net4;

string chiffré = EncryptionHelper.Encrypt("MonMotDePasse");
string clair   = EncryptionHelper.Decrypt(chiffré);

Versions sans exception, pratiques dans les initialisations :

if (EncryptionHelper.TryEncrypt("MonMotDePasse", out string chiffré)) { }
if (EncryptionHelper.TryDecrypt(chiffré, out string clair)) { }

đŸ·ïž DĂ©chiffrement automatique avec [Encrypted]

DĂ©corez les propriĂ©tĂ©s sensibles de votre objet de configuration, puis appelez ParseObject — tout est dĂ©chiffrĂ© en une seule passe, y compris les objets imbriquĂ©s.

Déclaration du modÚle

public class AppSettings
{
    public string ApiUrl { get; set; }

    [Encrypted]
    public string ApiKey { get; set; }

    [Encrypted]
    public DatabaseSettings Database { get; set; }
}

public class DatabaseSettings
{
    [Encrypted]
    public string ConnectionString { get; set; }
}

Déchiffrement

var settings = /* récupération depuis la configuration */;
EncryptionHelper.ParseObject(settings);
// ✅ settings.ApiKey et settings.Database.ConnectionString sont en clair
// ⚠ Database doit ĂȘtre dĂ©corĂ© avec [Encrypted] pour que la rĂ©cursion s'applique

Comportement en cas d'échec

Mode Comportement si le déchiffrement échoue
KeepValue (défaut) La valeur d'origine est conservée
ReplaceByEmpty La propriété est vidée ("")
[Encrypted(EncryptedAttributeModes.KeepValue)]
public string ApiKey { get; set; }

[Encrypted(EncryptedAttributeModes.ReplaceByEmpty)]
public string Secret { get; set; }

Profondeur de récursion

ParseObject descend jusqu'à 5 niveaux d'imbrication par défaut. Ce seuil est configurable :

EncryptionHelper.ParseObject(settings, maxLevel: 10);

💡 La rĂ©cursion ne s'applique qu'aux propriĂ©tĂ©s explicitement dĂ©corĂ©es avec [Encrypted]. Un objet imbriquĂ© non dĂ©corĂ© est ignorĂ©, mĂȘme s'il contient lui-mĂȘme des propriĂ©tĂ©s [Encrypted].


🔄 Migration vers .NET

Les valeurs chiffrées avec ce package ne sont pas directement compatibles avec Kapela.Security.Encryption. Deux options pour migrer :

Option 1 — Outil CLI (recommandĂ©)

dotnet tool install --global Kapela.Security.Encryption.Tools

Kapela-Encryption migrate -p NomDeMonApplication -v "<valeur chiffrée Net4>"
 >>> <nouvelle valeur Ă  placer dans appsettings.json>

Option 2 — Lecture transitoire dans le code

Dans l'application .NET cible, utilisez IsNet4 = true pour déchiffrer temporairement les anciennes valeurs le temps de les remplacer :

// Dans Kapela.Security.Encryption (.NET)
[Encrypted(IsNet4 = true)]
public string AncienMotDePasse { get; set; } = string.Empty;

đŸ› ïž GĂ©nĂ©rer des valeurs chiffrĂ©es

Utilisez l'outil CLI avec l'option --net4 :

Kapela-Encryption encrypt --net4 -p NomDeMonApplication -v "MonMotDePasse"
 >>> <valeur Ă  placer dans la configuration>
Product Compatible and additional computed target framework versions.
.NET Framework net48 is compatible.  net481 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.8

    • No dependencies.
  • .NETFramework 4.8.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.3 120 5/11/2026
4.0.2 105 4/7/2026
4.0.1 236 4/28/2025
1.0.1 220 4/2/2025
1.0.0 167 11/4/2024