aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-10-08 15:37:55 -0500
committerJP Dillingham <jp@dillingham.me>2022-10-08 15:37:55 -0500
commit216572289f0956ab9cb7461cc90b2f2c2c2f89a8 (patch)
tree5ab596ca640ae44e5525617358b9742c2db8a8a7 /tests
parent133feb54ef28ffe672b779ad422890887688d23a (diff)
downloadslskd-216572289f0956ab9cb7461cc90b2f2c2c2f89a8.tar.gz
fix bugs in AES enc
Diffstat (limited to 'tests')
-rw-r--r--tests/slskd.Tests.Unit/Common/Cryptography/AesTests.cs33
1 files changed, 33 insertions, 0 deletions
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);
+ }
+ }
+}