From 27db4aec1776cbb364954ff2815c6fc3bca25d09 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Tue, 26 May 2020 04:16:49 -0500 Subject: [PATCH] can now encrypt strings in cli menu --- cli/cli.csproj | 1 + cli/ui/interfaces/encrypt.cs | 19 +++++++++++++++---- tests/doublekeyPrivateTest.cs | 2 -- tests/doublekeyPublicTest.cs | 2 -- treasurechest/simplepack/Packed.cs | 16 ---------------- treasurechest/simplepack/pack.cs | 4 ++-- treasurechest/treasurechest.csproj | 1 - 7 files changed, 18 insertions(+), 27 deletions(-) delete mode 100644 treasurechest/simplepack/Packed.cs diff --git a/cli/cli.csproj b/cli/cli.csproj index bcdfb9e..d224f3c 100644 --- a/cli/cli.csproj +++ b/cli/cli.csproj @@ -7,6 +7,7 @@ + diff --git a/cli/ui/interfaces/encrypt.cs b/cli/ui/interfaces/encrypt.cs index 4cdd399..9a45874 100644 --- a/cli/ui/interfaces/encrypt.cs +++ b/cli/ui/interfaces/encrypt.cs @@ -1,8 +1,13 @@ using System.IO; using System; +using System.Text; using Sodium; +using niceware; + +using chestcrypto.simplepack; +using chestcrypto.symmetric; + using treasurechest.STDIOWrapper; -using getpass; namespace treasurechestCLI{ @@ -11,7 +16,7 @@ namespace treasurechestCLI{ int choice = 0; int counter = 1; byte[] key = new byte[32]; - string message; + byte[] message; string encrypted; translations.Strings strings = new translations.Strings(); @@ -48,13 +53,19 @@ namespace treasurechestCLI{ } if (choice == 1){ try { - message = GetMessage.getTypedMessage(); + message = UTF8Encoding.UTF8.GetBytes(GetMessage.getTypedMessage()); } catch(System.NullReferenceException){ continue; } + key = SecretBox.GenerateKey(); - //encrypted = + encrypted = SimplePack.pack(Symmetric.encrypt(message, key)); + STDIO.O(encrypted); + foreach (string word in Niceware.ToPassphrase(key)){ + Console.Write(word + " "); + } + STDIO.O(""); } else if (choice == encryptMenuOptions.Length){ diff --git a/tests/doublekeyPrivateTest.cs b/tests/doublekeyPrivateTest.cs index 0e0fba1..d56996d 100644 --- a/tests/doublekeyPrivateTest.cs +++ b/tests/doublekeyPrivateTest.cs @@ -43,7 +43,6 @@ namespace DoubleKeyPrivateTests success = true; } catch (chestcrypto.exceptions.InvalidDoubleKeyException){ - Console.WriteLine("Throws properly for too small array size"); } if (success){ Assert.Fail(); @@ -54,7 +53,6 @@ namespace DoubleKeyPrivateTests success = true; } catch (chestcrypto.exceptions.InvalidDoubleKeyException){ - Console.WriteLine("Throws properly for too large array size"); } if (success){ Assert.Fail(); diff --git a/tests/doublekeyPublicTest.cs b/tests/doublekeyPublicTest.cs index fe3a936..314db80 100644 --- a/tests/doublekeyPublicTest.cs +++ b/tests/doublekeyPublicTest.cs @@ -26,7 +26,6 @@ namespace DoubleKeyPublicTests success = true; } catch (chestcrypto.exceptions.InvalidDoubleKeyException){ - Console.WriteLine("Throws properly for too small array size"); } if (success){ Assert.Fail(); @@ -37,7 +36,6 @@ namespace DoubleKeyPublicTests success = true; } catch (chestcrypto.exceptions.InvalidDoubleKeyException){ - Console.WriteLine("Throws properly for too large array size"); } if (success){ Assert.Fail(); diff --git a/treasurechest/simplepack/Packed.cs b/treasurechest/simplepack/Packed.cs deleted file mode 100644 index 65afb64..0000000 --- a/treasurechest/simplepack/Packed.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace chestcrypto{ - - namespace simplepack{ - - public class Packed{ - //private string - //public override string ToString(){ - //} - public Packed(){ - - } - } - - } - -} \ No newline at end of file diff --git a/treasurechest/simplepack/pack.cs b/treasurechest/simplepack/pack.cs index d2865fb..5c9ba3a 100644 --- a/treasurechest/simplepack/pack.cs +++ b/treasurechest/simplepack/pack.cs @@ -6,8 +6,8 @@ namespace chestcrypto{ public class SimplePack{ - private const string header = "CHEST-MESSAGE"; - private const string footer = "END-CHEST-MESSAGE."; + private const string header = "CHEST-MESSAGE "; + private const string footer = " END-CHEST-MESSAGE."; // Test simplepackTest.TestPackUnpackBytes public static string pack(byte[] data){ diff --git a/treasurechest/treasurechest.csproj b/treasurechest/treasurechest.csproj index 29b365b..e9003db 100644 --- a/treasurechest/treasurechest.csproj +++ b/treasurechest/treasurechest.csproj @@ -7,7 +7,6 @@ -