From 216572289f0956ab9cb7461cc90b2f2c2c2f89a8 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 8 Oct 2022 15:37:55 -0500 Subject: fix bugs in AES enc --- .../Common/Cryptography/AesTests.cs | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/slskd.Tests.Unit/Common/Cryptography/AesTests.cs (limited to 'tests') diff --git a/tests/slskd.Tests.Unit/Common/Cryptography/AesTests.cs b/tests/slskd.Tests.Unit/Common/Cryptography/AesTests.cs new file mode 100644 index 00000000..c6c9be94 --- /dev/null +++ b/tests/slskd.Tests.Unit/Common/Cryptography/AesTests.cs @@ -0,0 +1,33 @@ +namespace slskd.Tests.Unit.Common.Cryptography +{ + using System.Text; + using slskd.Cryptography; + using Xunit; + + public class AesTests + { + [Fact] + public void Generates_Random_Keys_Of_Expected_Length() + { + var key = Aes.GenerateRandomKey(); + Assert.Equal(48, key.Length); + } + + [Fact] + public void Encrypts_And_Decrypts() + { + var plainText = "hello, world!"; + var plainBytes = Encoding.UTF8.GetBytes(plainText); + + var key = Aes.GenerateRandomKey(); + + var encryptedBytes = Aes.Encrypt(plainBytes, key); + + var decryptedBytes = Aes.Decrypt(encryptedBytes, key); + + var decryptedText = Encoding.UTF8.GetString(decryptedBytes); + + Assert.Equal(plainText, decryptedText); + } + } +} -- cgit v1.2.3