diff --git a/rinseoffcli/RinseOffCLI.cs b/rinseoffcli/RinseOffCLI.cs index 8c13967..ab5c72c 100644 --- a/rinseoffcli/RinseOffCLI.cs +++ b/rinseoffcli/RinseOffCLI.cs @@ -24,8 +24,10 @@ namespace rinseoffcli stderrStream.Flush(); } static void loadData(string filepath, string keypath){ + // Load in an encrypted file and use a key file to decrypt it, then log bytes back to stdout byte[] plaintext = {}; byte[] readBytes(string file){ + // Read bytes in from a file, exit with error message if not possible byte[] bytesToRead = {}; try{ bytesToRead = File.ReadAllBytes(file); @@ -46,6 +48,7 @@ namespace rinseoffcli } var stdout = Console.OpenStandardOutput(); try{ + // Decrypt a file using a key file plaintext = RinseOff.decrypt_secret_bytes( readBytes(filepath), readBytes(keypath) @@ -59,6 +62,7 @@ namespace rinseoffcli stderrWrite("Could not decrypt " + filepath + " with " + keypath); Environment.Exit(12); } + // print the plaintext and exit foreach(byte b in plaintext){ stdout.WriteByte(b); } diff --git a/tests/TestDecrypt.cs b/tests/TestDecrypt.cs index 6cdd3dc..a098a58 100644 --- a/tests/TestDecrypt.cs +++ b/tests/TestDecrypt.cs @@ -1,6 +1,7 @@ using NUnit.Framework; using System.Text; using System.Collections.Generic; +using Sodium; using rinseoff; namespace testDecrypted @@ -15,7 +16,18 @@ namespace testDecrypted [Test] public void testDecrypted() { + var key = Sodium.SecretBox.GenerateKey(); + var nonce = Sodium.SecretBox.GenerateNonce(); + var msg = Encoding.Default.GetBytes("hey"); + var encrypted = Sodium.SecretBox.Create(msg, nonce, key); + var combined = new List(); + combined.AddRange(nonce); + combined.AddRange(encrypted); + Assert.AreEqual( + RinseOff.decrypt_secret_bytes(combined.ToArray(), key), + msg + ); } } } \ No newline at end of file