C#注册机:
[C#] 纯文本查看 复制代码 /// <summary>
/// 获取注册码
/// </summary>
/// <param name="cpuID"> 机器码</param>
/// <returns></returns>
public string GetRegCode(string cpuID)
{
string sKey = "63011852";
string text5 = this.Encrypt(cpuID, sKey);
int num5 = text5.Length;
int start = num5 / 2;
string regPart_1 = text5.Substring(0,4);
string regPart_2 = text5.Substring(start-1,4);
string regPart_3 = text5.Substring(num5 - 8, 8);
string regCode = regPart_1 + regPart_2 + regPart_3;
return regCode;
}
/// <summary>
/// 加密函数
/// </summary>
/// <param name="pToEncrypt"> 待加密字符 </param>
/// <param name="sKey"> 一个Magic Number</param>
/// <returns></returns>
public string Encrypt(string pToEncrypt, string sKey)
{
DESCryptoServiceProvider dESCryptoServiceProvider = new DESCryptoServiceProvider();
byte[] bytes = Encoding.Default.GetBytes(pToEncrypt);
dESCryptoServiceProvider.Key = Encoding.ASCII.GetBytes(sKey);
dESCryptoServiceProvider.IV = Encoding.ASCII.GetBytes(sKey);
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream, dESCryptoServiceProvider.CreateEncryptor(), CryptoStreamMode.Write);
cryptoStream.Write(bytes, 0, bytes.Length);
cryptoStream.FlushFinalBlock();
StringBuilder stringBuilder = new StringBuilder();
byte[] array = memoryStream.ToArray();
checked
{
for (int i = 0; i < array.Length; i++)
{
byte b = array[i];
stringBuilder.AppendFormat("{0:X2}", b);
}
return stringBuilder.ToString();
}
} |