diff --git a/src/Security.Console/Infrastructure/EntryPoint.cs b/src/Security.Console/Infrastructure/EntryPoint.cs index 6df141c..40363f6 100644 --- a/src/Security.Console/Infrastructure/EntryPoint.cs +++ b/src/Security.Console/Infrastructure/EntryPoint.cs @@ -5,21 +5,42 @@ using System; using System.Linq; using System.Text; +using Security.Crypto; namespace Security.Console.Infrastructure { - public class EntryPoint + public static class EntryPoint { public static int Main(string[] args) { - return Parser.Default.ParseArguments(args) + return Parser.Default.ParseArguments(args) .MapResult( (GenerateKeyOptions options) => GenerateKey(options), (SplitSecretOptions options) => SplitSecret(options), (CombineOptions options) => Combine(options), (ToBase64Options options) => ToBase64(options), (FromBase64Options options) => FromBase64(options), - errs => 1); + (EncryptOptions options) => Encrypt(options), + _ => 1); + } + + private static int Encrypt(EncryptOptions options) + { + var key = Convert.FromBase64String(options.Key); + + var iv = Convert.FromBase64String(options.Iv); + + var salt = Convert.FromBase64String(options.Salt); + + var data = Convert.FromBase64String(options.Data); + + var cipher = new SymmetricCipher(); + + var encrypted = cipher.Encrypt(data, key, iv, salt); + + Output($"\n Encrypted data: {Convert.ToBase64String(encrypted)}"); + + return 0; } private static int GenerateKey(GenerateKeyOptions options) diff --git a/src/Security.Console/Infrastructure/Settings/EncryptOptions.cs b/src/Security.Console/Infrastructure/Settings/EncryptOptions.cs new file mode 100644 index 0000000..066c8b6 --- /dev/null +++ b/src/Security.Console/Infrastructure/Settings/EncryptOptions.cs @@ -0,0 +1,19 @@ +using CommandLine; + +namespace Security.Console.Infrastructure.Settings; + +[Verb("Encrypt", HelpText = "Encrypt some data.")] +public class EncryptOptions +{ + [Option('k', "Key", Required = true, HelpText = "Base 64 encoded key.")] + public string Key { get; set; } + + [Option('i', "IV", Required = true, HelpText = "Base 64 encoded initialisation vector.")] + public string Iv { get; set; } + + [Option('s', "Salt", Required = true, HelpText = "Base 64 encoded salt.")] + public string Salt { get; set; } + + [Option('d', "Data", Required = true, HelpText = "Base 64 encoded data to be encrypted.")] + public string Data { get; set; } +} \ No newline at end of file