配置文件升级+修改(重要更新!)

This commit is contained in:
2025-06-09 09:22:59 +08:00
parent a548d8f3f2
commit d111c8c2c0
27 changed files with 1880 additions and 1 deletions

19
U8Server/Util/GetSign.cs Normal file
View File

@@ -0,0 +1,19 @@
using System.Globalization;
using U8Server.Extensions;
namespace U8Server.Util
{
public class GetSign
{
public static string GetBy16Md5()
{
string appId = "gN9yId!!lfwaRoi3";
string appSecret = "xr35$IQAutBRX1UYhgOUY#CqChI#Y3b$";
string timestamp = DateTime.Now.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture);
string key = $"{appSecret}{appId}{timestamp}{appSecret}";
string sign = key.ToMD5Encrypt(uppercase: false, is16bit: true)
?? throw new InvalidOperationException("MD5加密失败");
return sign;
}
}
}

View File

@@ -0,0 +1,110 @@
using System.Security.Cryptography;
using System.Text;
namespace U8Server.Util
{
//
// 摘要:
// MD5 加密
public static class MD5Encryption
{
//
// 摘要:
// MD5 比较
//
// 参数:
// text:
// 加密文本
//
// hash:
// MD5 字符串
//
// uppercase:
// 是否输出大写加密,默认 false
//
// is16:
// 是否输出 16 位
//
// 返回结果:
// bool
public static bool Compare(string text, string hash, bool uppercase = false, bool is16 = false)
{
return Compare(Encoding.UTF8.GetBytes(text), hash, uppercase, is16);
}
//
// 摘要:
// MD5 加密
//
// 参数:
// text:
// 加密文本
//
// uppercase:
// 是否输出大写加密,默认 false
//
// is16:
// 是否输出 16 位
public static string Encrypt(string text, bool uppercase = false, bool is16 = false)
{
return Encrypt(Encoding.UTF8.GetBytes(text), uppercase, is16);
}
//
// 摘要:
// MD5 加密
//
// 参数:
// bytes:
// 字节数组
//
// uppercase:
// 是否输出大写加密,默认 false
//
// is16:
// 是否输出 16 位
public static string Encrypt(byte[] bytes, bool uppercase = false, bool is16 = false)
{
byte[] array = MD5.HashData(bytes);
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < array.Length; i++)
{
stringBuilder.Append(array[i].ToString("x2"));
}
string text = stringBuilder.ToString();
string text2 = ((!is16) ? text : text.Substring(8, 16));
if (uppercase)
{
return text2.ToUpper();
}
return text2;
}
//
// 摘要:
// MD5 比较
//
// 参数:
// bytes:
// 字节数组
//
// hash:
// MD5 字符串
//
// uppercase:
// 是否输出大写加密,默认 false
//
// is16:
// 是否输出 16 位
//
// 返回结果:
// bool
public static bool Compare(byte[] bytes, string hash, bool uppercase = false, bool is16 = false)
{
string value = Encrypt(bytes, uppercase, is16);
return hash.Equals(value, StringComparison.OrdinalIgnoreCase);
}
}
}

View File

@@ -0,0 +1,20 @@
using U8Server.Util;
namespace U8Server.Extensions
{
public static class StringExtensions
{
/// <summary>
/// 对字符串进行 MD5 加密(扩展方法)
/// </summary>
/// <param name="input">待加密的字符串</param>
/// <param name="uppercase">是否返回大写形式</param>
/// <param name="is16bit">是否返回 16 位 MD5默认 32 位)</param>
/// <returns>加密后的字符串</returns>
public static string ToMD5Encrypt(this string input, bool uppercase = false, bool is16bit = false)
{
// 直接调用现有的 MD5Encryption.Encrypt 方法
return MD5Encryption.Encrypt(input, uppercase, is16bit);
}
}
}