Kapela.Security.Encryption.Net4
4.0.2
Prefix Reserved
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
<PackageReference Include="Kapela.Security.Encryption.Net4" Version="4.0.2" />
<PackageVersion Include="Kapela.Security.Encryption.Net4" Version="4.0.2" />
<PackageReference Include="Kapela.Security.Encryption.Net4" />
paket add Kapela.Security.Encryption.Net4 --version 4.0.2
#r "nuget: Kapela.Security.Encryption.Net4, 4.0.2"
#:package Kapela.Security.Encryption.Net4@4.0.2
#addin nuget:?package=Kapela.Security.Encryption.Net4&version=4.0.2
#tool nuget:?package=Kapela.Security.Encryption.Net4&version=4.0.2
đ 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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net48 is compatible. net481 is compatible. |
-
.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.