2021-04-08 20:09:59 +08:00
|
|
|
|
using MongoDB.Driver;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
public static class AccountHelper
|
|
|
|
|
{
|
|
|
|
|
public static async ETTask<int> GetFirbiddenIpCount(string ip)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
List<ForbiddenIP> list = await DBComponent.Instance.QueryFilter(Builders<ForbiddenIP>.Filter.Eq(t => t.Ip, ip));
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (list != null && list.Count != 0)
|
|
|
|
|
{
|
|
|
|
|
ForbiddenIP forbiddenIP = list[0];
|
|
|
|
|
return forbiddenIP.count;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public sealed class SecurityUtil
|
|
|
|
|
{
|
|
|
|
|
public class SecurityData
|
|
|
|
|
{
|
|
|
|
|
public byte[] xorScale;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static readonly byte[] xorScale;
|
|
|
|
|
static SecurityUtil()
|
|
|
|
|
{
|
|
|
|
|
if (xorScale == null)
|
|
|
|
|
{
|
|
|
|
|
string path = Path.Combine(Environment.CurrentDirectory, "../Release/key");
|
|
|
|
|
string str = File.ReadAllText(path);
|
|
|
|
|
SecurityData data = MongoHelper.FromJson<SecurityData>(str);
|
|
|
|
|
xorScale = data.xorScale;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 对数组进行异或
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="buffer"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static byte[] Xor(byte[] buffer)
|
|
|
|
|
{
|
|
|
|
|
//------------------
|
|
|
|
|
//第3步:xor解密
|
|
|
|
|
//------------------
|
|
|
|
|
int iScaleLen = xorScale.Length;
|
|
|
|
|
for (int i = 0; i < buffer.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
buffer[i] = (byte)(buffer[i] ^ xorScale[i % iScaleLen]);
|
|
|
|
|
}
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|