Skip to content

Commit 7e99a83

Browse files
committed
Initial scaffolding.
1 parent 364aaeb commit 7e99a83

22 files changed

+802
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
# kryptera
1+
# kryptera
2+
3+
Kryptera is a quick-and-dirty .NET Core Tool to encrypt and decrypt files using AEAD AES-256-GCM, as well as an encryption key generator. Kryptera means "encrypt" in Swedish.
4+
5+
## Usage
6+
7+
## License
8+
9+
MIT

kryptera.sln

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31005.135
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kryptera.Tools", "src\Kryptera.Tools\Kryptera.Tools.csproj", "{7A3A3CE9-0F53-4CA7-BBD9-FFE63ECB3A64}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{730BE3AF-871D-4F7B-A5DB-B46D01A5BBA9}"
9+
ProjectSection(SolutionItems) = preProject
10+
README.md = README.md
11+
EndProjectSection
12+
EndProject
13+
Global
14+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
15+
Debug|Any CPU = Debug|Any CPU
16+
Release|Any CPU = Release|Any CPU
17+
EndGlobalSection
18+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
19+
{7A3A3CE9-0F53-4CA7-BBD9-FFE63ECB3A64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20+
{7A3A3CE9-0F53-4CA7-BBD9-FFE63ECB3A64}.Debug|Any CPU.Build.0 = Debug|Any CPU
21+
{7A3A3CE9-0F53-4CA7-BBD9-FFE63ECB3A64}.Release|Any CPU.ActiveCfg = Release|Any CPU
22+
{7A3A3CE9-0F53-4CA7-BBD9-FFE63ECB3A64}.Release|Any CPU.Build.0 = Release|Any CPU
23+
EndGlobalSection
24+
GlobalSection(SolutionProperties) = preSolution
25+
HideSolutionNode = FALSE
26+
EndGlobalSection
27+
GlobalSection(ExtensibilityGlobals) = postSolution
28+
SolutionGuid = {D2AF9F7A-452F-484F-9812-2CA2C0461DA3}
29+
EndGlobalSection
30+
EndGlobal

kryptera.sln.DotSettings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Kryptera/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace Kryptera.Tools.CommandLine
2+
{
3+
using System.CommandLine.Invocation;
4+
using System.CommandLine.Parsing;
5+
using Commands;
6+
using MediatR;
7+
using Microsoft.Extensions.DependencyInjection;
8+
using Microsoft.Extensions.Hosting;
9+
10+
public static class CommandHandlerFactory
11+
{
12+
public static ICommandHandler CreateFor<TRequest>() where TRequest : ICommandLineRequest, new()
13+
{
14+
return CommandHandler.Create(async (IHost host, ParseResult parseResult) =>
15+
{
16+
var mediator = host.Services.GetRequiredService<IMediator>();
17+
18+
var request = new TRequest();
19+
request.Map(parseResult);
20+
21+
// ReSharper disable once SuspiciousTypeConversion.Global
22+
if (request is IRequest<int> returnRequest)
23+
{
24+
return await mediator.Send(returnRequest);
25+
}
26+
27+
request.Map(parseResult);
28+
await mediator.Send(request);
29+
return 0;
30+
});
31+
}
32+
}
33+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
namespace Kryptera.Tools.CommandLine
2+
{
3+
using System.CommandLine;
4+
using System.IO;
5+
using Commands;
6+
7+
public class DecryptCommand : Command
8+
{
9+
internal static string CommandName = "decrypt";
10+
11+
public DecryptCommand() : base(CommandName, "Decrypt a file or directory using AES-256-GCM")
12+
{
13+
Initialize();
14+
}
15+
16+
protected void Initialize()
17+
{
18+
// arguments
19+
AddArgument(new Argument<FileSystemInfo>("source",
20+
"Specify the source file or directory")
21+
{Arity = ArgumentArity.ExactlyOne});
22+
23+
// options
24+
AddOption(new Option<string>(new[] {"-k", "/k", "--key"},
25+
"Specify encryption key"));
26+
27+
AddOption(new Option<FileSystemInfo>(new[] {"-o", "/o", "--output"},
28+
"Specify output file or directory"));
29+
30+
AddOption(new Option<bool>(new[] {"-f", "/f", "--force"},
31+
"Overwrite existing files"));
32+
33+
AddOption(new Option<bool>(new[] {"-c", "/c", "--console-only"},
34+
"Output the results to the console only"));
35+
36+
// handler
37+
Handler = CommandHandlerFactory.CreateFor<DecryptFiles>();
38+
}
39+
}
40+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
namespace Kryptera.Tools.CommandLine
2+
{
3+
using System.CommandLine;
4+
using System.IO;
5+
using Commands;
6+
7+
public class EncryptCommand : Command
8+
{
9+
public static string CommandName = "encrypt";
10+
11+
public EncryptCommand() : base(CommandName, "Encrypt a file or directory using AES-256-GCM")
12+
{
13+
Initialize();
14+
}
15+
16+
protected void Initialize()
17+
{
18+
// arguments
19+
AddArgument(new Argument<FileSystemInfo>("source",
20+
"Specify the source file or directory")
21+
{Arity = ArgumentArity.ExactlyOne});
22+
23+
// options
24+
AddOption(new Option<string>(new[] {"-k", "/k", "--key"},
25+
"Specify encryption key"));
26+
27+
AddOption(new Option<FileSystemInfo>(new[] {"-o", "/o", "--output"},
28+
"Specify output file or directory"));
29+
30+
AddOption(new Option<bool>(new[] {"-f", "/f", "--force"},
31+
"Overwrite existing files"));
32+
33+
AddOption(new Option<bool>(new[] {"-c", "/c", "--console-only"},
34+
"Output the results to the console only"));
35+
36+
// handler
37+
Handler = CommandHandlerFactory.CreateFor<EncryptFiles>();
38+
}
39+
}
40+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace Kryptera.Tools.CommandLine
2+
{
3+
using System.CommandLine;
4+
using Commands;
5+
6+
public class GenerateCommand : Command
7+
{
8+
public static string CommandName = "generate";
9+
10+
public GenerateCommand() : base(CommandName, "Generate a new AES-256 key")
11+
{
12+
Initialize();
13+
}
14+
15+
protected void Initialize()
16+
{
17+
// handler
18+
Handler = CommandHandlerFactory.CreateFor<GenerateEncryptionKey>();
19+
}
20+
}
21+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
namespace Kryptera.Tools.CommandLine
2+
{
3+
using System;
4+
using System.CommandLine;
5+
using System.CommandLine.Help;
6+
using System.Drawing;
7+
using System.Reflection;
8+
using Pastel;
9+
10+
public class KrypteraHelpBuilder : HelpBuilder
11+
{
12+
public static readonly Lazy<string> AssemblyVersion =
13+
new(() =>
14+
{
15+
var assembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();
16+
var assemblyVersionAttribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
17+
return assemblyVersionAttribute is null
18+
? assembly.GetName().Version?.ToString()
19+
: assemblyVersionAttribute.InformationalVersion;
20+
});
21+
22+
public KrypteraHelpBuilder(IConsole console) : base(console)
23+
{
24+
}
25+
26+
public override void Write(ICommand command)
27+
{
28+
var color = Color.FromArgb(0, 119, 102); // teal
29+
var asciiArtStrings = new[]
30+
{
31+
"",
32+
$" {"@w".Pastel(color)}",
33+
$" {"\"".Pastel(color)}"
34+
};
35+
36+
if (command.Name.Equals(KrypteraRootCommand.AssemblyName, StringComparison.OrdinalIgnoreCase))
37+
{
38+
//foreach (var line in asciiArtStrings)
39+
//{
40+
// System.Console.WriteLine(line);
41+
//}
42+
43+
System.Console.WriteLine($"Kryptera {AssemblyVersion.Value.Pastel(Color.DarkOrange)}\n");
44+
}
45+
46+
base.Write(command);
47+
}
48+
}
49+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Kryptera.Tools.CommandLine
2+
{
3+
using Microsoft.Extensions.Logging;
4+
5+
public class KrypteraOptions
6+
{
7+
public LogLevel Verbosity { get; set; } = LogLevel.Warning;
8+
}
9+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace Kryptera.Tools.CommandLine
2+
{
3+
using System.CommandLine;
4+
using System.CommandLine.Invocation;
5+
6+
public class KrypteraRootCommand : RootCommand
7+
{
8+
public static string AssemblyName => typeof(KrypteraRootCommand).Assembly.GetName().Name!.ToLowerInvariant();
9+
10+
public KrypteraRootCommand()
11+
{
12+
Initialize();
13+
}
14+
15+
protected void Initialize()
16+
{
17+
Name = AssemblyName;
18+
19+
AddCommand(new EncryptCommand());
20+
AddCommand(new DecryptCommand());
21+
AddCommand(new GenerateCommand());
22+
23+
Handler = CommandHandler.Create<IConsole>(console =>
24+
{
25+
new KrypteraHelpBuilder(console).Write(this);
26+
});
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)