4 Commits

Author SHA1 Message Date
Developer 02
0804ea1418 refactor: RSA-Kryptografie-Klassen für bessere Flexibilität und Effizienz überarbeitet
- Konstruktoren zu `RSACryptographer`, `RSADecryptor` und `RSAEncryptor` hinzugefügt, um die Initialisierung zu verbessern.
- `PublicKeyPem` in `RSADecryptor` optimiert, um unnötige Objekterstellungen zu vermeiden.
- `Verify`-Methode in `RSAEncryptor` korrigiert, um eine korrekte Signaturprüfung zu gewährleisten.
- Code-Wiederverwendbarkeit verbessert, indem Base64-Konvertierungslogik zentralisiert wurde.
2024-11-16 03:24:19 +01:00
Developer 02
84dbca97d5 feat(Core.Security): Erstellte Erweiterungsmethoden 2024-11-16 02:14:28 +01:00
Developer 02
8c350db146 chore: update gitignroe 2024-11-14 10:26:07 +01:00
Developer 02
471dace359 feat: Projekt initialisieren 2024-11-14 09:59:14 +01:00
11 changed files with 103 additions and 29 deletions

1
.gitignore vendored
View File

@@ -408,3 +408,4 @@ FodyWeavers.xsd
/DigitalData.Core.ConsoleApp/DigitalData.Core.ConsoleApp.csproj
/DigitalData.Core.ConsoleApp/Program.cs
/DigitalData.Core.ConsoleApp/FooHttpOptions.cs
/DigitalData.Core.Tests/obj/

View File

@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,13 @@
namespace DigitalData.Core.Security
{
public static class Extensions
{
public static string ToBase64String(this byte[] bytes) => Convert.ToBase64String(bytes);
public static byte[] Base64ToByte(this string base64String) => Convert.FromBase64String(base64String);
public static byte[] ToBytes(this string str) => System.Text.Encoding.UTF8.GetBytes(str);
public static string BytesToString(this byte[] bytes) => System.Text.Encoding.UTF8.GetString(bytes);
}
}

View File

@@ -0,0 +1,21 @@
using System.Security.Cryptography;
namespace DigitalData.Core.Security
{
public class RSACryptographer
{
internal RSACryptographer() { }
public required string Pem
{
init
{
_rsa.ImportFromPem(value);
}
}
public required RSAEncryptionPadding Padding { get; init; }
protected readonly RSA _rsa = RSA.Create();
}
}

View File

@@ -0,0 +1,25 @@
using System.Security.Cryptography;
namespace DigitalData.Core.Security
{
public class RSADecryptor : RSACryptographer
{
public string PublicKeyPem => _rsa.ExportRSAPublicKeyPem();
public RSAEncryptor Encryptor
{
get
{
return new ()
{
Pem = PublicKeyPem,
Padding = Padding
};
}
}
public byte[] Decrypt(byte[] data) => _rsa.Decrypt(data, Padding);
public string Decrypt(string data) => _rsa.Decrypt(data.Base64ToByte(), Padding).BytesToString();
}
}

View File

@@ -0,0 +1,11 @@
namespace DigitalData.Core.Security
{
public class RSAEncryptor : RSACryptographer
{
public byte[] Encrypt(byte[] data) => _rsa.Encrypt(data, Padding);
public string Encrypt(string data) => _rsa.Encrypt(data.Base64ToByte(), Padding).BytesToString();
public bool Verify(string data, string signature) => Encrypt(data) == signature;
}
}

View File

@@ -0,0 +1,14 @@
using System.Security.Cryptography;
namespace DigitalData.Core.Security
{
public static class RSAExtensions
{
public static RSA ToRSA(this string pem)
{
var rsa = RSA.Create();
rsa.ImportFromPem(pem);
return rsa;
}
}
}

View File

@@ -2,7 +2,7 @@
using DigitalData.Core.Client;
using Microsoft.Extensions.DependencyInjection;
namespace DigitalData.Core.Tests
namespace DigitalData.Core.Tests.Client
{
[TestFixture]
public class BaseHttpClientServiceTests

View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
@@ -26,6 +26,7 @@
<ProjectReference Include="..\DigitalData.Core.Client\DigitalData.Core.Client.csproj" />
<ProjectReference Include="..\DigitalData.Core.DTO\DigitalData.Core.DTO.csproj" />
<ProjectReference Include="..\DigitalData.Core.Infrastructure\DigitalData.Core.Infrastructure.csproj" />
<ProjectReference Include="..\DigitalData.Core.Security\DigitalData.Core.Security.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\tekh\.nuget\packages\;D:\ProgramFiles\DevExpress 21.2\Components\Offline Packages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.9.1</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\tekh\.nuget\packages\" />
<SourceRoot Include="D:\ProgramFiles\DevExpress 21.2\Components\Offline Packages\" />
</ItemGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)nunit3testadapter\4.3.0\build\netcoreapp2.1\NUnit3TestAdapter.props" Condition="Exists('$(NuGetPackageRoot)nunit3testadapter\4.3.0\build\netcoreapp2.1\NUnit3TestAdapter.props')" />
<Import Project="$(NuGetPackageRoot)nunit\3.13.3\build\NUnit.props" Condition="Exists('$(NuGetPackageRoot)nunit\3.13.3\build\NUnit.props')" />
<Import Project="$(NuGetPackageRoot)microsoft.testplatform.testhost\17.3.2\build\netcoreapp2.1\Microsoft.TestPlatform.TestHost.props" Condition="Exists('$(NuGetPackageRoot)microsoft.testplatform.testhost\17.3.2\build\netcoreapp2.1\Microsoft.TestPlatform.TestHost.props')" />
<Import Project="$(NuGetPackageRoot)microsoft.codecoverage\17.3.2\build\netstandard1.0\Microsoft.CodeCoverage.props" Condition="Exists('$(NuGetPackageRoot)microsoft.codecoverage\17.3.2\build\netstandard1.0\Microsoft.CodeCoverage.props')" />
<Import Project="$(NuGetPackageRoot)microsoft.net.test.sdk\17.3.2\build\netcoreapp2.1\Microsoft.NET.Test.Sdk.props" Condition="Exists('$(NuGetPackageRoot)microsoft.net.test.sdk\17.3.2\build\netcoreapp2.1\Microsoft.NET.Test.Sdk.props')" />
<Import Project="$(NuGetPackageRoot)microsoft.entityframeworkcore\7.0.16\buildTransitive\net6.0\Microsoft.EntityFrameworkCore.props" Condition="Exists('$(NuGetPackageRoot)microsoft.entityframeworkcore\7.0.16\buildTransitive\net6.0\Microsoft.EntityFrameworkCore.props')" />
</ImportGroup>
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<PkgNUnit_Analyzers Condition=" '$(PkgNUnit_Analyzers)' == '' ">C:\Users\tekh\.nuget\packages\nunit.analyzers\3.5.0</PkgNUnit_Analyzers>
</PropertyGroup>
</Project>

View File

@@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigitalData.Core.Legacy.Tes
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigitalData.Core.Legacy.Client", "DigitalData.Core.Legacy.Client\DigitalData.Core.Legacy.Client.csproj", "{E009A053-A9F4-48F2-984F-EF5C376A9B14}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigitalData.Core.Security", "DigitalData.Core.Security\DigitalData.Core.Security.csproj", "{47D80C65-74A2-4EB8-96A5-D571A9108FB3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -62,6 +64,10 @@ Global
{E009A053-A9F4-48F2-984F-EF5C376A9B14}.Debug|Any CPU.Build.0 = Release|Any CPU
{E009A053-A9F4-48F2-984F-EF5C376A9B14}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E009A053-A9F4-48F2-984F-EF5C376A9B14}.Release|Any CPU.Build.0 = Release|Any CPU
{47D80C65-74A2-4EB8-96A5-D571A9108FB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{47D80C65-74A2-4EB8-96A5-D571A9108FB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{47D80C65-74A2-4EB8-96A5-D571A9108FB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{47D80C65-74A2-4EB8-96A5-D571A9108FB3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE