Skip to content

Commit 9091eaf

Browse files
committed
Network/Security: AES key generation
1 parent 9176238 commit 9091eaf

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

Client/Security/AesEncryptor.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ public static class AesEncryptor
1212
{
1313
private static Aes aes;
1414
private static byte[] ivec = { 255, 254, 253, 252, 251, 250, 249, 248, 60, 61, 62, 63, 64, 65, 66, 67 };
15+
private static byte[] key = new byte[16];
1516

16-
public static string Key { get; private set; }
17+
public static byte[] Key { get { return key; } }
1718

1819
// Incializes AES instance
1920
public static void Inicialize()
@@ -22,9 +23,13 @@ public static void Inicialize()
2223
aes.Clear();
2324

2425
aes = Aes.Create();
26+
using (var rng = new RNGCryptoServiceProvider())
27+
{
28+
rng.GetBytes(key);
29+
}
30+
2531
aes.IV = ivec;
26-
Key = "yayayaIamLordeya";
27-
aes.Key = System.Text.Encoding.ASCII.GetBytes(Key);
32+
aes.Key = key;
2833
aes.Padding = PaddingMode.Zeros;
2934
}
3035

Client/Security/RsaEncryptor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ public static void Inicialize()
4949
}
5050

5151
// Encrypts data
52-
public static byte[] Encrypt(string toEncrypt)
52+
public static byte[] Encrypt(byte[] toEncrypt)
5353
{
5454
if (rsa == null)
5555
return null;
5656

57-
return rsa.Encrypt(System.Text.Encoding.ASCII.GetBytes(toEncrypt), false);
57+
return rsa.Encrypt(toEncrypt, false);
5858
}
5959

6060
// Clears allocated resources

0 commit comments

Comments
 (0)