-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathAuth.cs
More file actions
113 lines (95 loc) · 3.7 KB
/
Auth.cs
File metadata and controls
113 lines (95 loc) · 3.7 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Security.Cryptography;
using System.Text;
namespace SamFirm.Utils
{
internal static class Crypto
{
public static string DecryptStringFromBytes(byte[] cipherText, byte[] Key)
{
// Check arguments.
if (cipherText == null || cipherText.Length <= 0)
throw new ArgumentNullException("cipherText");
if (Key == null || Key.Length <= 0)
throw new ArgumentNullException("Key");
// Declare the string used to hold
// the decrypted text.
string plaintext = null;
// Create an Aes object
// with the specified key.
using (Aes aesAlg = Aes.Create())
{
aesAlg.Mode = CipherMode.CBC;
aesAlg.Key = Key;
aesAlg.IV = Key[0..16];
// Create a decryptor
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
plaintext = Encoding.ASCII.GetString(decryptor.TransformFinalBlock(cipherText, 0, cipherText.Length));
decryptor.Dispose();
}
return plaintext;
}
public static byte[] EncryptStringToBytes(string plainText, byte[] Key)
{
// Check arguments.
if (plainText == null || plainText.Length <= 0)
throw new ArgumentNullException("plainText");
if (Key == null || Key.Length <= 0)
throw new ArgumentNullException("Key");
byte[] encrypted;
// Create an Aes object
// with the specified key.
using (Aes aesAlg = Aes.Create())
{
aesAlg.Mode = CipherMode.CBC;
aesAlg.Key = Key;
aesAlg.IV = Key[0..16];
// Create an encryptor
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
encrypted = encryptor.TransformFinalBlock(Encoding.ASCII.GetBytes(plainText), 0, Encoding.ASCII.GetBytes(plainText).Length);
encryptor.Dispose();
}
// Return the encrypted bytes.
return encrypted;
}
}
internal static class Auth
{
private const string NONCE_KEY = "vicopx7dqu06emacgpnpy8j8zwhduwlh";
private const string AUTH_KEY = "9u7qab84rpc16gvk";
public static string DecryptNonce(string nonce)
{
return Crypto.DecryptStringFromBytes(Convert.FromBase64String(nonce), Encoding.ASCII.GetBytes(NONCE_KEY.ToString()));
}
public static string GetAuthorization(string decryptedNonce)
{
StringBuilder key = new StringBuilder();
for (int i = 0; i < 16; i++)
{
int nonceChar = decryptedNonce[i];
key.Append(NONCE_KEY[nonceChar % 16]);
}
key.Append(AUTH_KEY);
return Convert.ToBase64String(Crypto.EncryptStringToBytes(decryptedNonce, Encoding.ASCII.GetBytes(key.ToString())));
}
public static string GetLogicCheck(string input, string decryptedNonce)
{
if (string.IsNullOrEmpty(input))
{
return string.Empty;
}
StringBuilder builder = new StringBuilder();
int num = 0;
foreach (char ch in decryptedNonce)
{
int num2 = ch & '\x000f';
if (input.Length <= (num2 + num))
{
return string.Empty;
}
builder.Append(input[num2 + num]);
}
return builder.ToString();
}
}
}