Browse Source

feat(encryption): Added SM4 encryption algorithm integration

pull/1088/head
colin 1 year ago
parent
commit
e6b4790fa9
  1. 21
      Directory.Packages.props
  2. 516
      aspnet-core/LINGYUN.MicroService.Common.sln
  3. 7
      aspnet-core/LINGYUN.MicroService.SingleProject.sln
  4. 26
      aspnet-core/framework/console/LINGYUN.Abp.Encryption.Console/AbpEncryptionConsoleModule.cs
  5. 4
      aspnet-core/framework/console/LINGYUN.Abp.Encryption.Console/LINGYUN.Abp.Encryption.Console.csproj
  6. 3
      aspnet-core/framework/security/LINGYUN.Abp.Encryption.SM4/FodyWeavers.xml
  7. 30
      aspnet-core/framework/security/LINGYUN.Abp.Encryption.SM4/FodyWeavers.xsd
  8. 21
      aspnet-core/framework/security/LINGYUN.Abp.Encryption.SM4/LINGYUN.Abp.Encryption.SM4.csproj
  9. 10
      aspnet-core/framework/security/LINGYUN.Abp.Encryption.SM4/LINGYUN/Abp/Encryption/SM4/AbpEncryptionSM4Module.cs
  10. 73
      aspnet-core/framework/security/LINGYUN.Abp.Encryption.SM4/LINGYUN/Abp/Encryption/SM4/SM4StringEncryptionService.cs
  11. 14
      aspnet-core/framework/security/LINGYUN.Abp.Encryption.SM4/README.md
  12. 25
      aspnet-core/tests/LINGYUN.Abp.Encryption.SM4.Tests/LINGYUN.Abp.Encryption.SM4.Tests.csproj
  13. 8
      aspnet-core/tests/LINGYUN.Abp.Encryption.SM4.Tests/LINGYUN/Abp/Encryption/SM4/AbpEncryptionSM4TestBase.cs
  14. 12
      aspnet-core/tests/LINGYUN.Abp.Encryption.SM4.Tests/LINGYUN/Abp/Encryption/SM4/AbpEncryptionSM4TestModule.cs
  15. 27
      aspnet-core/tests/LINGYUN.Abp.Encryption.SM4.Tests/LINGYUN/Abp/Encryption/SM4/StringEncryptionService_Tests.cs

21
Directory.Packages.props

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<DotNetCoreCAPPackageVersion>8.2.0</DotNetCoreCAPPackageVersion> <DotNetCoreCAPPackageVersion>8.2.0</DotNetCoreCAPPackageVersion>
<ElsaPackageVersion>2.14.1</ElsaPackageVersion> <ElsaPackageVersion>2.14.1</ElsaPackageVersion>
<ElsaNextPackageVersion>3.2.3</ElsaNextPackageVersion> <ElsaNextPackageVersion>3.3.0-rc7</ElsaNextPackageVersion>
<VoloAbpPackageVersion>8.3.0</VoloAbpPackageVersion> <VoloAbpPackageVersion>8.3.0</VoloAbpPackageVersion>
<LINGYUNAbpPackageVersion>8.3.0</LINGYUNAbpPackageVersion> <LINGYUNAbpPackageVersion>8.3.0</LINGYUNAbpPackageVersion>
<MicrosoftExtensionsPackageVersion>8.0.0</MicrosoftExtensionsPackageVersion> <MicrosoftExtensionsPackageVersion>8.0.0</MicrosoftExtensionsPackageVersion>
@ -147,6 +147,7 @@
<PackageVersion Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="$(MicrosoftAspNetCorePackageVersion)" /> <PackageVersion Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="$(MicrosoftAspNetCorePackageVersion)" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" /> <PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" /> <PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="$(MicrosoftEntityFrameworkCorePackageVersion)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="$(MicrosoftEntityFrameworkCorePackageVersion)" /> <PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="$(MicrosoftEntityFrameworkCorePackageVersion)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="$(MicrosoftEntityFrameworkCorePackageVersion)" /> <PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="$(MicrosoftEntityFrameworkCorePackageVersion)" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="$(MicrosoftExtensionsPackageVersion)" /> <PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="$(MicrosoftExtensionsPackageVersion)" />
@ -157,6 +158,8 @@
<PackageVersion Include="Microsoft.Extensions.Http.Polly" Version="$(MicrosoftExtensionsPackageVersion)" /> <PackageVersion Include="Microsoft.Extensions.Http.Polly" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="$(MicrosoftExtensionsPackageVersion)" /> <PackageVersion Include="Microsoft.Extensions.Hosting" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.2" /> <PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.12.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
</ItemGroup> </ItemGroup>
<!-- Elsa --> <!-- Elsa -->
<ItemGroup> <ItemGroup>
@ -179,6 +182,21 @@
<PackageVersion Include="Elsa.Webhooks.Persistence.EntityFramework.SqlServer" Version="$(ElsaPackageVersion)" /> <PackageVersion Include="Elsa.Webhooks.Persistence.EntityFramework.SqlServer" Version="$(ElsaPackageVersion)" />
<PackageVersion Include="Elsa.WorkflowSettings.Persistence.EntityFramework.SqlServer" Version="$(ElsaPackageVersion)" /> <PackageVersion Include="Elsa.WorkflowSettings.Persistence.EntityFramework.SqlServer" Version="$(ElsaPackageVersion)" />
</ItemGroup> </ItemGroup>
<!-- Elsa Next-->
<ItemGroup>
<PackageVersion Include="Elsa.Api.Client" Version="$(ElsaNextPackageVersion)" />
<PackageVersion Include="Elsa.Studio" Version="$(ElsaNextPackageVersion)" />
<PackageVersion Include="Elsa.Studio.Core.BlazorServer" Version="$(ElsaNextPackageVersion)" />
<PackageVersion Include="Elsa.Studio.Login.BlazorServer" Version="$(ElsaNextPackageVersion)" />
<PackageVersion Include="Elsa.Studio.Localization.BlazorServer" Version="$(ElsaNextPackageVersion)" />
<PackageVersion Include="Elsa.Studio.Core.BlazorWasm" Version="$(ElsaNextPackageVersion)" />
<PackageVersion Include="Elsa.Studio.Login.BlazorWasm" Version="$(ElsaNextPackageVersion)" />
<PackageVersion Include="Elsa.Studio.Translations" Version="$(ElsaNextPackageVersion)" />
<PackageVersion Include="Elsa.Studio.Agents" Version="$(ElsaNextPackageVersion)" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.20" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.20" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="7.0.20" />
</ItemGroup>
<!-- DotNetCore.CAP --> <!-- DotNetCore.CAP -->
<ItemGroup> <ItemGroup>
<PackageVersion Include="DotNetCore.CAP" Version="$(DotNetCoreCAPPackageVersion)" /> <PackageVersion Include="DotNetCore.CAP" Version="$(DotNetCoreCAPPackageVersion)" />
@ -226,6 +244,7 @@
<PackageVersion Include="aliyun-net-sdk-core" Version="1.5.10" /> <PackageVersion Include="aliyun-net-sdk-core" Version="1.5.10" />
<PackageVersion Include="Aliyun.OSS.SDK.NetCore" Version="2.13.0" /> <PackageVersion Include="Aliyun.OSS.SDK.NetCore" Version="2.13.0" />
<PackageVersion Include="AgileConfig.Client" Version="1.6.9" /> <PackageVersion Include="AgileConfig.Client" Version="1.6.9" />
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.5.0" />
<PackageVersion Include="Dapr.Client" Version="1.12.0" /> <PackageVersion Include="Dapr.Client" Version="1.12.0" />
<PackageVersion Include="Dapr.Actors" Version="1.12.0" /> <PackageVersion Include="Dapr.Actors" Version="1.12.0" />
<PackageVersion Include="Dapr.Actors.AspNetCore" Version="1.12.0" /> <PackageVersion Include="Dapr.Actors.AspNetCore" Version="1.12.0" />

516
aspnet-core/LINGYUN.MicroService.Common.sln

File diff suppressed because it is too large

7
aspnet-core/LINGYUN.MicroService.SingleProject.sln

@ -616,6 +616,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.AuditLogging.IP
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LY.MicroService.Applications.Single.EntityFrameworkCore.MySql", "migrations\LY.MicroService.Applications.Single.EntityFrameworkCore.MySql\LY.MicroService.Applications.Single.EntityFrameworkCore.MySql.csproj", "{746813A9-4221-42D8-AAB5-66CB69EC844F}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LY.MicroService.Applications.Single.EntityFrameworkCore.MySql", "migrations\LY.MicroService.Applications.Single.EntityFrameworkCore.MySql\LY.MicroService.Applications.Single.EntityFrameworkCore.MySql.csproj", "{746813A9-4221-42D8-AAB5-66CB69EC844F}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Encryption.SM4", "framework\security\LINGYUN.Abp.Encryption.SM4\LINGYUN.Abp.Encryption.SM4.csproj", "{15106D95-EE9A-4C9D-AB12-41FBE46A9A89}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -1622,6 +1624,10 @@ Global
{746813A9-4221-42D8-AAB5-66CB69EC844F}.Debug|Any CPU.Build.0 = Debug|Any CPU {746813A9-4221-42D8-AAB5-66CB69EC844F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{746813A9-4221-42D8-AAB5-66CB69EC844F}.Release|Any CPU.ActiveCfg = Release|Any CPU {746813A9-4221-42D8-AAB5-66CB69EC844F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{746813A9-4221-42D8-AAB5-66CB69EC844F}.Release|Any CPU.Build.0 = Release|Any CPU {746813A9-4221-42D8-AAB5-66CB69EC844F}.Release|Any CPU.Build.0 = Release|Any CPU
{15106D95-EE9A-4C9D-AB12-41FBE46A9A89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{15106D95-EE9A-4C9D-AB12-41FBE46A9A89}.Debug|Any CPU.Build.0 = Debug|Any CPU
{15106D95-EE9A-4C9D-AB12-41FBE46A9A89}.Release|Any CPU.ActiveCfg = Release|Any CPU
{15106D95-EE9A-4C9D-AB12-41FBE46A9A89}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -1921,6 +1927,7 @@ Global
{5BE31786-EAAB-4C86-8FFF-C07F27FBFD1C} = {99B7CBDE-A251-4738-97F0-DB1DB484BEE1} {5BE31786-EAAB-4C86-8FFF-C07F27FBFD1C} = {99B7CBDE-A251-4738-97F0-DB1DB484BEE1}
{77B3C7A4-15C7-4EFF-8451-4F13B4CCA4AE} = {C22741F9-FC56-4AE3-B543-9F15C779D345} {77B3C7A4-15C7-4EFF-8451-4F13B4CCA4AE} = {C22741F9-FC56-4AE3-B543-9F15C779D345}
{746813A9-4221-42D8-AAB5-66CB69EC844F} = {0D69B63D-F082-4D57-9FF0-355642C56993} {746813A9-4221-42D8-AAB5-66CB69EC844F} = {0D69B63D-F082-4D57-9FF0-355642C56993}
{15106D95-EE9A-4C9D-AB12-41FBE46A9A89} = {99B7CBDE-A251-4738-97F0-DB1DB484BEE1}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {711A43C0-A2F8-4E5C-9B9F-F2551E4B3FF1} SolutionGuid = {711A43C0-A2F8-4E5C-9B9F-F2551E4B3FF1}

26
aspnet-core/framework/console/LINGYUN.Abp.Encryption.Console/AbpEncryptionConsoleModule.cs

@ -1,22 +1,20 @@
using System.Text; using LINGYUN.Abp.Encryption.SM4;
using System.Text;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.Security;
using Volo.Abp.Security.Encryption; using Volo.Abp.Security.Encryption;
namespace LINGYUN.Abp.Encryption.Console namespace LINGYUN.Abp.Encryption.Console;
[DependsOn(typeof(AbpEncryptionSM4Module))]
public class AbpEncryptionConsoleModule : AbpModule
{ {
[DependsOn( public override void ConfigureServices(ServiceConfigurationContext context)
typeof(AbpSecurityModule))]
public class AbpEncryptionConsoleModule : AbpModule
{ {
public override void ConfigureServices(ServiceConfigurationContext context) Configure<AbpStringEncryptionOptions>(options =>
{ {
Configure<AbpStringEncryptionOptions>(options => options.DefaultPassPhrase = "s46c5q55nxpeS8Ra";
{ options.InitVectorBytes = Encoding.ASCII.GetBytes("s83ng0abvd02js84");
options.DefaultPassPhrase = "s46c5q55nxpeS8Ra"; options.DefaultSalt = Encoding.ASCII.GetBytes("sf&5)s3#");
options.InitVectorBytes = Encoding.ASCII.GetBytes("s83ng0abvd02js84"); });
options.DefaultSalt = Encoding.ASCII.GetBytes("sf&5)s3#");
});
}
} }
} }

4
aspnet-core/framework/console/LINGYUN.Abp.Encryption.Console/LINGYUN.Abp.Encryption.Console.csproj

@ -11,4 +11,8 @@
<PackageReference Include="Volo.Abp.Security" /> <PackageReference Include="Volo.Abp.Security" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\security\LINGYUN.Abp.Encryption.SM4\LINGYUN.Abp.Encryption.SM4.csproj" />
</ItemGroup>
</Project> </Project>

3
aspnet-core/framework/security/LINGYUN.Abp.Encryption.SM4/FodyWeavers.xml

@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ConfigureAwait ContinueOnCapturedContext="false" />
</Weavers>

30
aspnet-core/framework/security/LINGYUN.Abp.Encryption.SM4/FodyWeavers.xsd

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" />
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>

21
aspnet-core/framework/security/LINGYUN.Abp.Encryption.SM4/LINGYUN.Abp.Encryption.SM4.csproj

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\..\configureawait.props" />
<Import Project="..\..\..\..\common.props" />
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
<AssemblyName>LINGYUN.Abp.Encryption.SM4</AssemblyName>
<PackageId>LINGYUN.Abp.Encryption.SM4</PackageId>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Security" />
<PackageReference Include="BouncyCastle.Cryptography" />
</ItemGroup>
</Project>

10
aspnet-core/framework/security/LINGYUN.Abp.Encryption.SM4/LINGYUN/Abp/Encryption/SM4/AbpEncryptionSM4Module.cs

@ -0,0 +1,10 @@
using Volo.Abp.Modularity;
using Volo.Abp.Security;
namespace LINGYUN.Abp.Encryption.SM4;
[DependsOn(typeof(AbpSecurityModule))]
public class AbpEncryptionSM4Module : AbpModule
{
}

73
aspnet-core/framework/security/LINGYUN.Abp.Encryption.SM4/LINGYUN/Abp/Encryption/SM4/SM4StringEncryptionService.cs

@ -0,0 +1,73 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Modes;
using Org.BouncyCastle.Crypto.Paddings;
using Org.BouncyCastle.Crypto.Parameters;
using System;
using System.Security.Cryptography;
using System.Text;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Security.Encryption;
namespace LINGYUN.Abp.Encryption.SM4;
[Dependency(ServiceLifetime.Transient, ReplaceServices = true)]
[ExposeServices(typeof(StringEncryptionService), typeof(IStringEncryptionService))]
public class SM4StringEncryptionService : StringEncryptionService
{
public SM4StringEncryptionService(
IOptions<AbpStringEncryptionOptions> options)
: base(options)
{
}
public override string Decrypt(string cipherText, string passPhrase = null, byte[] salt = null)
{
if (string.IsNullOrEmpty(cipherText))
{
return null;
}
passPhrase ??= Options.DefaultPassPhrase;
salt ??= Options.DefaultSalt;
var cipherTextBytes = Convert.FromBase64String(cipherText);
using var password = new Rfc2898DeriveBytes(passPhrase, salt);
// 128-bit key
var keyBytes = password.GetBytes(16);
var ivBytes = password.GetBytes(16);
var cipher = new PaddedBufferedBlockCipher(new CbcBlockCipher(new SM4Engine()), new Pkcs7Padding());
cipher.Init(false, new ParametersWithIV(new KeyParameter(keyBytes), ivBytes));
var decryptTextBytes = cipher.DoFinal(cipherTextBytes);
return Encoding.UTF8.GetString(decryptTextBytes);
}
public override string Encrypt(string plainText, string passPhrase = null, byte[] salt = null)
{
if (plainText == null)
{
return null;
}
passPhrase ??= Options.DefaultPassPhrase;
salt ??= Options.DefaultSalt;
var plainTextBytes = Encoding.UTF8.GetBytes(plainText);
using var password = new Rfc2898DeriveBytes(passPhrase, salt);
// 128-bit key
var keyBytes = password.GetBytes(16);
var ivBytes = password.GetBytes(16);
var cipher = new PaddedBufferedBlockCipher(new CbcBlockCipher(new SM4Engine()), new Pkcs7Padding());
cipher.Init(true, new ParametersWithIV(new KeyParameter(keyBytes), ivBytes));
var decryptTextBytes = cipher.DoFinal(plainTextBytes);
return Convert.ToBase64String(decryptTextBytes);
}
}

14
aspnet-core/framework/security/LINGYUN.Abp.Encryption.SM4/README.md

@ -0,0 +1,14 @@
# LINGYUN.Abp.Encryption.SM4
数据加密模块,采用国密SM4算法,使用 **AbpStringEncryptionOptions** 配置无缝切换(密钥长度固定为128位以符合算法要求)
## 配置使用
```csharp
[DependsOn(typeof(AbpEncryptionSM4Module))]
public class YouProjectModule : AbpModule
{
// other
}
```

25
aspnet-core/tests/LINGYUN.Abp.Encryption.SM4.Tests/LINGYUN.Abp.Encryption.SM4.Tests.csproj

@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace />
<IsPackable>false</IsPackable>
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\framework\security\LINGYUN.Abp.Encryption.SM4\LINGYUN.Abp.Encryption.SM4.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.TestBase\LINGYUN.Abp.TestsBase.csproj" />
</ItemGroup>
</Project>

8
aspnet-core/tests/LINGYUN.Abp.Encryption.SM4.Tests/LINGYUN/Abp/Encryption/SM4/AbpEncryptionSM4TestBase.cs

@ -0,0 +1,8 @@
using LINGYUN.Abp.Tests;
namespace LINGYUN.Abp.Encryption.SM4;
public abstract class AbpEncryptionSM4TestBase : AbpTestsBase<AbpEncryptionSM4TestModule>
{
}

12
aspnet-core/tests/LINGYUN.Abp.Encryption.SM4.Tests/LINGYUN/Abp/Encryption/SM4/AbpEncryptionSM4TestModule.cs

@ -0,0 +1,12 @@
using Volo.Abp.Modularity;
namespace LINGYUN.Abp.Encryption.SM4;
[DependsOn(typeof(AbpEncryptionSM4Module))]
public class AbpEncryptionSM4TestModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
}
}

27
aspnet-core/tests/LINGYUN.Abp.Encryption.SM4.Tests/LINGYUN/Abp/Encryption/SM4/StringEncryptionService_Tests.cs

@ -0,0 +1,27 @@
using Shouldly;
using Volo.Abp.Security.Encryption;
using Xunit;
namespace LINGYUN.Abp.Encryption.SM4;
public class StringEncryptionService_Tests : AbpEncryptionSM4TestBase
{
private readonly IStringEncryptionService _stringEncryptionService;
public StringEncryptionService_Tests()
{
_stringEncryptionService = GetRequiredService<IStringEncryptionService>();
}
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData("This is a plain text!")]
public void Should_Enrypt_And_Decrpyt_With_Default_Options(string plainText)
{
var encryptedText = _stringEncryptionService.Encrypt(plainText);
var decryptedText = _stringEncryptionService.Decrypt(encryptedText);
decryptedText.ShouldBe(plainText);
}
}
Loading…
Cancel
Save