Skip to content
Snippets Groups Projects
Commit 76115c4c authored by Klaus Fischer's avatar Klaus Fischer
Browse files

feature: creating encryption test console project

parent 8182e078
No related branches found
No related tags found
1 merge request!112Draft: Feature/1731 big files encryption
......@@ -24,6 +24,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ValidationTests", "Tests\Va
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeyManagement", "KeyManagement\KeyManagement.csproj", "{D872CF15-8E00-4DD5-AB22-3DEA783F251F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EncryptionConsoleRunner", "Tests\EncryptionConsoleRunner\EncryptionConsoleRunner.csproj", "{4C58A2CD-9408-43EA-823A-64FE7BDFBFD3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -74,6 +76,10 @@ Global
{D872CF15-8E00-4DD5-AB22-3DEA783F251F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D872CF15-8E00-4DD5-AB22-3DEA783F251F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D872CF15-8E00-4DD5-AB22-3DEA783F251F}.Release|Any CPU.Build.0 = Release|Any CPU
{4C58A2CD-9408-43EA-823A-64FE7BDFBFD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C58A2CD-9408-43EA-823A-64FE7BDFBFD3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C58A2CD-9408-43EA-823A-64FE7BDFBFD3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C58A2CD-9408-43EA-823A-64FE7BDFBFD3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{27115A99-2AE8-42BC-9495-BE2DCEDDF1E8} = {180029B5-8DD3-4594-B34E-6C07AF1C52C5}
......@@ -84,5 +90,6 @@ Global
{8428631D-E396-4685-BE34-5E6C3307EE97} = {180029B5-8DD3-4594-B34E-6C07AF1C52C5}
{29874608-52A5-49B0-A806-7F076750FE02} = {180029B5-8DD3-4594-B34E-6C07AF1C52C5}
{DDEFDA59-FD75-4F25-9BA2-8DAE22B4A0B0} = {180029B5-8DD3-4594-B34E-6C07AF1C52C5}
{4C58A2CD-9408-43EA-823A-64FE7BDFBFD3} = {180029B5-8DD3-4594-B34E-6C07AF1C52C5}
EndGlobalSection
EndGlobal
FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Tests/EncryptionConsoleRunner/EncryptionConsoleRunner.csproj", "Tests/EncryptionConsoleRunner/"]
RUN dotnet restore "Tests/EncryptionConsoleRunner/EncryptionConsoleRunner.csproj"
COPY . .
WORKDIR "/src/Tests/EncryptionConsoleRunner"
RUN dotnet build "EncryptionConsoleRunner.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "EncryptionConsoleRunner.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "EncryptionConsoleRunner.dll"]
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<Content Include="..\..\.dockerignore">
<Link>.dockerignore</Link>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\FitConnect\FitConnect.csproj" />
<ProjectReference Include="..\..\JwkGenerator\JwkGenerator.csproj" />
<ProjectReference Include="..\..\KeyManagement\KeyManagement.csproj" />
</ItemGroup>
</Project>
// See https://aka.ms/new-console-template for more information
using System.ComponentModel;
using System.Security.Cryptography;
using FitConnect.Encryption;
using FitConnect.KeyManagement;
Console.WriteLine("Hello, World!");
var keySet = new FitConnect.KeyManagement.Generator().CreateKeys();
EncryptLargeFiles_ShouldPass(750, keySet.publicKey.ToJson());
void EncryptLargeFiles_ShouldPass(int fileSizeInMb, string publicKey) {
// Arrange
var sourceFile = RandomNumberGenerator.GetBytes(1024 * 1024 * fileSizeInMb);
Console.WriteLine($"Encrypting {fileSizeInMb} MB file");
var encryption = new FitEncryption(publicKey, null);
// Act
var encryptedFile = encryption.Encrypt(sourceFile);
// Assert
}
void FindMaxFileSizeForEncryption(string publicKey) {
for (var start = 750; start < 800; start++) {
Console.Write($"Trying to encrypt {start} MB file");
try {
EncryptLargeFiles_ShouldPass(start, publicKey);
Console.WriteLine("...success");
}
catch (Exception e) {
Console.WriteLine("...failed");
Console.WriteLine(e);
Console.WriteLine($"Max file size for encryption is {start - 1} MB");
break;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment