这是加密和解密代码
namespace Zddr.School.Register
{
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text; public class Crypto
{
public string DesDecrypt(string strText, string sDecrKey)
{
byte[] bytes = null;
byte[] buffer2 = new byte[] { 0x12, 0x34, 0x56, 120, 0x90, 0xab, 0xcd, 0xef };
byte[] buffer3 = new byte[strText.get_Length()];
try
{
bytes = Encoding.get_UTF8().GetBytes(sDecrKey.Substring(0, 8));
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
buffer3 = Convert.FromBase64String(strText);
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, provider.CreateDecryptor(bytes, buffer2), 1);
stream2.Write(buffer3, 0, buffer3.Length);
stream2.FlushFinalBlock();
Encoding encoding = new UTF8Encoding();
return encoding.GetString(stream.ToArray());
}
catch (Exception exception)
{
return ("error:" + exception.get_Message() + "\r");
}
} public string DesEncrypt(string strText, string strEncrKey)
{
byte[] bytes = null;
byte[] buffer2 = new byte[] { 0x12, 0x34, 0x56, 120, 0x90, 0xab, 0xcd, 0xef };
try
{
bytes = Encoding.get_UTF8().GetBytes(strEncrKey.Substring(0, 8));
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
byte[] buffer3 = Encoding.get_UTF8().GetBytes(strText);
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, provider.CreateEncryptor(bytes, buffer2), 1);
stream2.Write(buffer3, 0, buffer3.Length);
stream2.FlushFinalBlock();
return Convert.ToBase64String(stream.ToArray());
}
catch (Exception exception)
{
return ("error:" + exception.get_Message() + "\r");
}
} public string RijndaelDecrypt(string strText, string strEncrKey)
{
try
{
byte[] bytes = Encoding.get_Default().GetBytes(strEncrKey.Substring(0, 8));
byte[] buffer2 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0 };
Rijndael rijndael = Rijndael.Create();
byte[] buffer3 = Convert.FromBase64String(strText);
ICryptoTransform transform = rijndael.CreateDecryptor(bytes, buffer2);
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, transform, 1);
stream2.Write(buffer3, 0, buffer3.Length);
stream2.FlushFinalBlock();
Encoding encoding = new UTF8Encoding();
return encoding.GetString(stream.ToArray());
}
catch (Exception exception)
{
return exception.get_Message();
}
} public string RijndaelEncrypt(string strText, string strEncrKey)
{
try
{
byte[] bytes = Encoding.get_Default().GetBytes(strEncrKey.Substring(0, 8));
byte[] buffer2 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0 };
byte[] buffer3 = Encoding.get_UTF8().GetBytes(strText);
ICryptoTransform transform = Rijndael.Create().CreateEncryptor(bytes, buffer2);
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, transform, 1);
stream2.Write(buffer3, 0, buffer3.Length);
stream2.FlushFinalBlock();
return Convert.ToBase64String(stream.ToArray());
}
catch (Exception exception)
{
return exception.get_Message();
}
}
}
}这是获取MAC的地址代码
namespace Zddr.School.Register
{
using System;
using System.Management; public class MacAddress
{
private MacAddress()
{
} internal static string GetMac()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration");
foreach (ManagementObject obj2 in searcher.Get())
{
if (obj2.get_Item("IPEnabled").ToString() == "True")
{
return obj2.get_Item("MacAddress").ToString();
}
}
return "";
}
}
}这是注册代码:namespace Zddr.School.Register
{
using System;
using System.Text;
using Zddr.School.Common;
using Zddr.School.Common.Security; public class Reg
{
public static bool CheckReg(string regCode)
{
bool flag = false;
try
{
Crypto crypto = new Crypto();
string[] strArray = crypto.DesDecrypt(regCode, "123456789").Split(new char[] { ',' });
string str2 = strArray[0];
string str3 = strArray[1];
string str4 = strArray[2];
string str5 = strArray[3];
if (GetRegCode() != str4)
{
return flag;
}
DbHelper helper = DbHelper.Instance();
helper.Open();
string commandText = "select count(*) from Sys_RegInfo";
if (*(helper.ExecuteScalar(commandText)) > 0)
{
commandText = "update Sys_RegInfo set RegCode='" + regCode + "'";
}
else
{
commandText = "insert into Sys_RegInfo(RegCode) values('" + regCode + "')";
}
helper.ExecuteNonQuery(commandText);
helper.Close();
flag = true;
}
catch
{
return false;
}
return flag;
} private static string Get3MD5(string str)
{
HashSignature signature = new HashSignature();
string signatureStr = signature.GetSignatureStr(str);
StringBuilder builder = new StringBuilder();
for (int i = signatureStr.get_Length() - 1; i > -1; i--)
{
builder.Append(signatureStr.get_Chars(i));
}
signatureStr = signature.GetSignatureStr(builder.ToString());
signatureStr = signature.GetSignatureStr(signatureStr);
string str3 = "";
for (int j = 0; j < signatureStr.get_Length(); j += 2)
{
if ((j > 0) && ((j % 8) == 0))
{
str3 = str3 + "-";
}
str3 = str3 + signatureStr.get_Chars(j);
}
return str3;
} public static string GetCharacterCode()
{
string mac = MacAddress.GetMac();
string str2 = "";
string signatureStr = new HashSignature().GetSignatureStr(mac);
for (int i = 0; i < signatureStr.get_Length(); i += 2)
{
str2 = str2 + signatureStr.get_Chars(i);
}
return str2;
} private static string GetRegCode()
{
return Get3MD5(GetCharacterCode());
} public static bool IsRegOk()
{
bool flag = false;
DbHelper helper = DbHelper.Instance();
helper.Open();
string commandText = "select RegCode from Sys_RegInfo";
object obj2 = helper.ExecuteScalar(commandText);
if (obj2 != null)
{
string strText = obj2.ToString();
try
{
Crypto crypto = new Crypto();
string[] strArray = crypto.DesDecrypt(strText, "123456789").Split(new char[] { ',' });
string str4 = strArray[0];
string str5 = strArray[1];
string str6 = strArray[2];
string str7 = strArray[3];
if ((GetRegCode().CompareTo(str6) == 0) && ((Convert.ToDateTime(str4).AddMonths(Convert.ToInt32(str5)) >= DateTime.get_Now()) || (str5 == "-1")))
{
flag = true;
}
}
catch
{
}
}
helper.Close();
return flag;
}
}
}怎么写注册机呀?我就是对这个方面很弱!麻烦高手帮个忙?我的电子
namespace Zddr.School.Register
{
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text; public class Crypto
{
public string DesDecrypt(string strText, string sDecrKey)
{
byte[] bytes = null;
byte[] buffer2 = new byte[] { 0x12, 0x34, 0x56, 120, 0x90, 0xab, 0xcd, 0xef };
byte[] buffer3 = new byte[strText.get_Length()];
try
{
bytes = Encoding.get_UTF8().GetBytes(sDecrKey.Substring(0, 8));
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
buffer3 = Convert.FromBase64String(strText);
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, provider.CreateDecryptor(bytes, buffer2), 1);
stream2.Write(buffer3, 0, buffer3.Length);
stream2.FlushFinalBlock();
Encoding encoding = new UTF8Encoding();
return encoding.GetString(stream.ToArray());
}
catch (Exception exception)
{
return ("error:" + exception.get_Message() + "\r");
}
} public string DesEncrypt(string strText, string strEncrKey)
{
byte[] bytes = null;
byte[] buffer2 = new byte[] { 0x12, 0x34, 0x56, 120, 0x90, 0xab, 0xcd, 0xef };
try
{
bytes = Encoding.get_UTF8().GetBytes(strEncrKey.Substring(0, 8));
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
byte[] buffer3 = Encoding.get_UTF8().GetBytes(strText);
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, provider.CreateEncryptor(bytes, buffer2), 1);
stream2.Write(buffer3, 0, buffer3.Length);
stream2.FlushFinalBlock();
return Convert.ToBase64String(stream.ToArray());
}
catch (Exception exception)
{
return ("error:" + exception.get_Message() + "\r");
}
} public string RijndaelDecrypt(string strText, string strEncrKey)
{
try
{
byte[] bytes = Encoding.get_Default().GetBytes(strEncrKey.Substring(0, 8));
byte[] buffer2 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0 };
Rijndael rijndael = Rijndael.Create();
byte[] buffer3 = Convert.FromBase64String(strText);
ICryptoTransform transform = rijndael.CreateDecryptor(bytes, buffer2);
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, transform, 1);
stream2.Write(buffer3, 0, buffer3.Length);
stream2.FlushFinalBlock();
Encoding encoding = new UTF8Encoding();
return encoding.GetString(stream.ToArray());
}
catch (Exception exception)
{
return exception.get_Message();
}
} public string RijndaelEncrypt(string strText, string strEncrKey)
{
try
{
byte[] bytes = Encoding.get_Default().GetBytes(strEncrKey.Substring(0, 8));
byte[] buffer2 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0 };
byte[] buffer3 = Encoding.get_UTF8().GetBytes(strText);
ICryptoTransform transform = Rijndael.Create().CreateEncryptor(bytes, buffer2);
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, transform, 1);
stream2.Write(buffer3, 0, buffer3.Length);
stream2.FlushFinalBlock();
return Convert.ToBase64String(stream.ToArray());
}
catch (Exception exception)
{
return exception.get_Message();
}
}
}
}这是获取MAC的地址代码
namespace Zddr.School.Register
{
using System;
using System.Management; public class MacAddress
{
private MacAddress()
{
} internal static string GetMac()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration");
foreach (ManagementObject obj2 in searcher.Get())
{
if (obj2.get_Item("IPEnabled").ToString() == "True")
{
return obj2.get_Item("MacAddress").ToString();
}
}
return "";
}
}
}这是注册代码:namespace Zddr.School.Register
{
using System;
using System.Text;
using Zddr.School.Common;
using Zddr.School.Common.Security; public class Reg
{
public static bool CheckReg(string regCode)
{
bool flag = false;
try
{
Crypto crypto = new Crypto();
string[] strArray = crypto.DesDecrypt(regCode, "123456789").Split(new char[] { ',' });
string str2 = strArray[0];
string str3 = strArray[1];
string str4 = strArray[2];
string str5 = strArray[3];
if (GetRegCode() != str4)
{
return flag;
}
DbHelper helper = DbHelper.Instance();
helper.Open();
string commandText = "select count(*) from Sys_RegInfo";
if (*(helper.ExecuteScalar(commandText)) > 0)
{
commandText = "update Sys_RegInfo set RegCode='" + regCode + "'";
}
else
{
commandText = "insert into Sys_RegInfo(RegCode) values('" + regCode + "')";
}
helper.ExecuteNonQuery(commandText);
helper.Close();
flag = true;
}
catch
{
return false;
}
return flag;
} private static string Get3MD5(string str)
{
HashSignature signature = new HashSignature();
string signatureStr = signature.GetSignatureStr(str);
StringBuilder builder = new StringBuilder();
for (int i = signatureStr.get_Length() - 1; i > -1; i--)
{
builder.Append(signatureStr.get_Chars(i));
}
signatureStr = signature.GetSignatureStr(builder.ToString());
signatureStr = signature.GetSignatureStr(signatureStr);
string str3 = "";
for (int j = 0; j < signatureStr.get_Length(); j += 2)
{
if ((j > 0) && ((j % 8) == 0))
{
str3 = str3 + "-";
}
str3 = str3 + signatureStr.get_Chars(j);
}
return str3;
} public static string GetCharacterCode()
{
string mac = MacAddress.GetMac();
string str2 = "";
string signatureStr = new HashSignature().GetSignatureStr(mac);
for (int i = 0; i < signatureStr.get_Length(); i += 2)
{
str2 = str2 + signatureStr.get_Chars(i);
}
return str2;
} private static string GetRegCode()
{
return Get3MD5(GetCharacterCode());
} public static bool IsRegOk()
{
bool flag = false;
DbHelper helper = DbHelper.Instance();
helper.Open();
string commandText = "select RegCode from Sys_RegInfo";
object obj2 = helper.ExecuteScalar(commandText);
if (obj2 != null)
{
string strText = obj2.ToString();
try
{
Crypto crypto = new Crypto();
string[] strArray = crypto.DesDecrypt(strText, "123456789").Split(new char[] { ',' });
string str4 = strArray[0];
string str5 = strArray[1];
string str6 = strArray[2];
string str7 = strArray[3];
if ((GetRegCode().CompareTo(str6) == 0) && ((Convert.ToDateTime(str4).AddMonths(Convert.ToInt32(str5)) >= DateTime.get_Now()) || (str5 == "-1")))
{
flag = true;
}
}
catch
{
}
}
helper.Close();
return flag;
}
}
}怎么写注册机呀?我就是对这个方面很弱!麻烦高手帮个忙?我的电子
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货