-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToken.cs
31 lines (27 loc) · 1.1 KB
/
Token.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System.Security.Cryptography;
using System.Text;
using ServerTCP.Сryptographies;
namespace ServerTCP
{
public class Token
{
private static string Key = "sdkjoidarkmilk=";
public static Dictionary<string, string> Tokens = new Dictionary<string, string>();
public static string GenerateToken(string login, string password)
{
//var tokenData = string.Concat(login, ",", password);
var regToken = string.Concat(login, ",", DateTime.Now);
using (var myAes = Aes.Create())
{
byte[] aesKey = SHA256Managed.Create().ComputeHash(Encoding.UTF8.GetBytes(Key));
byte[] aesIV = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(Key));
myAes.Key = aesKey;
myAes.IV = aesIV;
var tokenResult = Convert.ToBase64String(CryptoAes.EncryptStringToBytes_Aes(regToken, myAes.Key, myAes.IV));
if(!Tokens.ContainsKey(tokenResult))
Tokens.Add(tokenResult, regToken);
return tokenResult;
}
}
}
}