forked from ivanmeler/SamFirm_Reborn
-
Notifications
You must be signed in to change notification settings - Fork 3
/
KiesAuth.cs
59 lines (53 loc) · 1.78 KB
/
KiesAuth.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace SamFirm
{
public static class KiesAuth
{
private const string KEY_1 = "vicopx7dqu06emacgpnpy8j8zwhduwlh";
private const string KEY_2 = "9u7qab84rpc16gvk";
public static byte[] DecryptNonce(string inp)
{
using (AesManaged aes = new AesManaged())
{
byte[] bytes = Convert.FromBase64String(inp);
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.PKCS7;
byte[] key = Encoding.UTF8.GetBytes(KEY_1);
byte[] iv = key.Take(16).ToArray();
aes.Key = key;
aes.IV = iv;
var decryptor = aes.CreateDecryptor(key, iv);
byte[] decrypted = decryptor.TransformFinalBlock(bytes, 0, bytes.Length);
return decrypted;
}
}
public static string GetAuth(byte[] nonce)
{
var keydata = nonce.Select(c => c % 16).ToArray();
var fkey = get_fkey(keydata);
using (AesManaged aes = new AesManaged())
{
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.PKCS7;
byte[] iv = fkey.Take(16).ToArray();
var encryptor = aes.CreateEncryptor(fkey, iv);
byte[] auth = encryptor.TransformFinalBlock(nonce, 0, nonce.Length);
return Convert.ToBase64String(auth);
}
}
public static byte[] get_fkey(int[] inp)
{
var key = "";
for (int i = 0; i < 16; i++)
{
key += KEY_1[inp[i]];
}
key += KEY_2;
return Encoding.UTF8.GetBytes(key);
}
}
}