From 137910aeb403163d248945b8fd1c63d8910be563 Mon Sep 17 00:00:00 2001 From: enisn Date: Tue, 13 Apr 2021 14:38:05 +0300 Subject: [PATCH 1/5] Docs - Add initial state of String Encryption --- docs/en/String-Encryption.md | 135 ++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 2 deletions(-) diff --git a/docs/en/String-Encryption.md b/docs/en/String-Encryption.md index bc2a9c6c7e..3e4d40b22b 100644 --- a/docs/en/String-Encryption.md +++ b/docs/en/String-Encryption.md @@ -1,4 +1,135 @@ -# String Encryption +# String Encryption -TODO! +ABP Framework provides string encryption feature that allows to **Encrypt** and **Decrypt** strings. + + +## Installation + +> This package is already installed by default with the startup template. So, most of the time, you don't need to install it manually. + +If installation is needed, it is suggested to use the [ABP CLI](https://docs.abp.io/en/abp/latest/CLI) to install this package. + +### Using the ABP CLI + +Open a command line window in the folder of the project (.csproj file) and type the following command: + +```bash +abp add-package Volo.Abp.GlobalFeatures +``` + +### Manual Installation + +If you want to manually install; + +1. Add the [Volo.Abp.Security]([NuGet Gallery | Volo.Abp.Security 4.2.2](https://www.nuget.org/packages/Volo.Abp.Security)) NuGet package to your project: + + `Install-Package Volo.Abp.Security` + +2. Add the `AbpSecurityModule` to the dependency list of your module: + + ```csharp + [DependsOn( + //...other dependencies + typeof(AbpSecurityModule) // <-- Add module dependency like that + )] + public class YourModule : AbpModule + { + } + ``` + + + +## Using String Encryption + +All encryption operations are included in `IStringEncryptionService`. You can inject it and start to use. + +```csharp + public class MyService : DomainService + { + public IStringEncryptionService StringEncryptionService { get; } + + public MyAppService(IStringEncryptionService stringEncryptionService) + { + StringEncryptionService = stringEncryptionService; + } + + public string Encrypt(string value) + { + // To enrcypt a value + return StringEncryptionService.Encrypt(value); + } + + public string Decrpyt(string value) + { + // To decrypt a value + return StringEncryptionService.Decrypt(value); + } + } +``` + + + +### Using Custom PassPhrase + +`IStringEncryptionService` methods has **passPharase** parameter with default value and it uses default PassPhrase when you don't pass passPhrase parameter. + +Default value is `gsKnGZ041HLL4IM8` + +```csharp +StringEncryptionService.Encrypt(value); // Default Pass Phrase +StringEncryptionService.Encrypt(value, "MyCustomPassPhrase"); // Custom Pass Phrase + +// Encrypt & Decrypt have same parameters. +StringEncryptionService.Decrypt(value, "MyCustomPassPhrase"); +``` + + + +### Using Custom Salt + +`IStringEncryptionService` methods has **salt** parameter with default value and it uses default Salt when you don't pass the parameter. + +Default value is `Encoding.ASCII.GetBytes("hgt!16kl")` + +```csharp +StringEncryptionService.Encrypt(value); // Default Salt +StringEncryptionService.Encrypt(value, salt: Encoding.UTF8.GetBytes("MyCustomSalt")); // Custom Salt + +// Encrypt & Decrypt have same parameters. +StringEncryptionService.Decrypt(value, salt: Encoding.UTF8.GetBytes("MyCustomSalt")); +``` + + + +*** + +## String Encryption Options + +Default values can be configured with `AbpStringEncryptionOptions` type. + +```csharp +Configure(opts => +{ + opts.DefaultPassPhrase = "MyStrongPassPhrase"; + opts.DefaultSalt = Encoding.UTF8.GetBytes("MyStrongSalt"); + opts.InitVectorBytes = Encoding.UTF8.GetBytes("YetAnotherStrongSalt"); + opts.Keysize = 512; +}); +``` + + + +- **DefaultPassPhrase**: Default password to encrypt/decrypt texts. It's recommended to set to another value for security. Default value: `gsKnGZ041HLL4IM8` + +- **DefaultSalt**: A value which is used as salt while encrypting/decrypting. + + Default value: `Encoding.ASCII.GetBytes("hgt!16kl")` + +- **InitVectorBytes:** This constant string is used as a "salt" value for the PasswordDeriveBytes function calls. This size of the IV (in bytes) must = (keysize / 8). Default keysize is 256, so the IV must be 32 bytes long. Using a 16 character string here gives us 32 bytes when converted to a byte array. + + Default value: `Encoding.ASCII.GetBytes("jkE49230Tf093b42")` + +- **Keysize:** This constant is used to determine the keysize of the encryption algorithm. + + Default value: `256` \ No newline at end of file From f747b948999cbbc7f51ef94388a236ad438db41e Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Wed, 14 Apr 2021 09:44:19 +0300 Subject: [PATCH 2/5] Update docs/en/String-Encryption.md Co-authored-by: Qingxiao Ren --- docs/en/String-Encryption.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/String-Encryption.md b/docs/en/String-Encryption.md index 3e4d40b22b..bda0cc86e4 100644 --- a/docs/en/String-Encryption.md +++ b/docs/en/String-Encryption.md @@ -15,7 +15,7 @@ If installation is needed, it is suggested to use the [ABP CLI](https://docs.abp Open a command line window in the folder of the project (.csproj file) and type the following command: ```bash -abp add-package Volo.Abp.GlobalFeatures +abp add-package Volo.Abp.Security ``` ### Manual Installation @@ -132,4 +132,4 @@ Configure(opts => - **Keysize:** This constant is used to determine the keysize of the encryption algorithm. - Default value: `256` \ No newline at end of file + Default value: `256` From eee85d35fa9ada20753b00174df598418e57035e Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Wed, 14 Apr 2021 09:46:24 +0300 Subject: [PATCH 3/5] Update docs/en/String-Encryption.md --- docs/en/String-Encryption.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/String-Encryption.md b/docs/en/String-Encryption.md index bda0cc86e4..76f0d2baa4 100644 --- a/docs/en/String-Encryption.md +++ b/docs/en/String-Encryption.md @@ -22,7 +22,7 @@ abp add-package Volo.Abp.Security If you want to manually install; -1. Add the [Volo.Abp.Security]([NuGet Gallery | Volo.Abp.Security 4.2.2](https://www.nuget.org/packages/Volo.Abp.Security)) NuGet package to your project: +1. Add the [Volo.Abp.Security](https://www.nuget.org/packages/Volo.Abp.Security) NuGet package to your project: `Install-Package Volo.Abp.Security` From ff71af7ec8bb8f844404a1c8bbe1d9bfba6cbebb Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 15 Apr 2021 15:14:40 +0300 Subject: [PATCH 4/5] Docs - Add String Encryption to Navigation --- docs/en/docs-nav.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/en/docs-nav.json b/docs/en/docs-nav.json index 4d2b2419c2..80651b346f 100644 --- a/docs/en/docs-nav.json +++ b/docs/en/docs-nav.json @@ -332,6 +332,10 @@ "text": "Object to Object Mapping", "path": "Object-To-Object-Mapping.md" }, + { + "text":"String Encryption", + "path":"String-Encryption.md" + }, { "text": "Text Templating", "path": "Text-Templating.md" From 05d6752947fa83373d3dcd6c3ab9f3db15a808fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 15 Apr 2021 15:28:39 +0300 Subject: [PATCH 5/5] Revision for string-encryption document --- docs/en/String-Encryption.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/docs/en/String-Encryption.md b/docs/en/String-Encryption.md index 76f0d2baa4..81bb4f119a 100644 --- a/docs/en/String-Encryption.md +++ b/docs/en/String-Encryption.md @@ -2,8 +2,6 @@ ABP Framework provides string encryption feature that allows to **Encrypt** and **Decrypt** strings. - - ## Installation > This package is already installed by default with the startup template. So, most of the time, you don't need to install it manually. @@ -38,8 +36,6 @@ If you want to manually install; } ``` - - ## Using String Encryption All encryption operations are included in `IStringEncryptionService`. You can inject it and start to use. @@ -68,14 +64,10 @@ All encryption operations are included in `IStringEncryptionService`. You can in } ``` - - ### Using Custom PassPhrase `IStringEncryptionService` methods has **passPharase** parameter with default value and it uses default PassPhrase when you don't pass passPhrase parameter. -Default value is `gsKnGZ041HLL4IM8` - ```csharp StringEncryptionService.Encrypt(value); // Default Pass Phrase StringEncryptionService.Encrypt(value, "MyCustomPassPhrase"); // Custom Pass Phrase @@ -84,14 +76,10 @@ StringEncryptionService.Encrypt(value, "MyCustomPassPhrase"); // Custom Pass Phr StringEncryptionService.Decrypt(value, "MyCustomPassPhrase"); ``` - - ### Using Custom Salt `IStringEncryptionService` methods has **salt** parameter with default value and it uses default Salt when you don't pass the parameter. -Default value is `Encoding.ASCII.GetBytes("hgt!16kl")` - ```csharp StringEncryptionService.Encrypt(value); // Default Salt StringEncryptionService.Encrypt(value, salt: Encoding.UTF8.GetBytes("MyCustomSalt")); // Custom Salt @@ -100,8 +88,6 @@ StringEncryptionService.Encrypt(value, salt: Encoding.UTF8.GetBytes("MyCustomSal StringEncryptionService.Decrypt(value, salt: Encoding.UTF8.GetBytes("MyCustomSalt")); ``` - - *** ## String Encryption Options @@ -118,8 +104,6 @@ Configure(opts => }); ``` - - - **DefaultPassPhrase**: Default password to encrypt/decrypt texts. It's recommended to set to another value for security. Default value: `gsKnGZ041HLL4IM8` - **DefaultSalt**: A value which is used as salt while encrypting/decrypting.