C# 獲取硬盤(pán)號(hào),CPU信息,加密解密技術(shù)的步驟
在我們編寫(xiě)好一款軟件后,我們不想別人盜用我們的軟件,這時(shí)候我們可以采用注冊(cè)的方式來(lái)保護(hù)我們的作品。這時(shí)候我們可能就需要簡(jiǎn)單了解一下加密解密技術(shù),下面是我的簡(jiǎn)單總結(jié):
第一步:程序獲得運(yùn)行機(jī)的唯一標(biāo)示(比如:網(wǎng)卡號(hào),CPU編號(hào),硬盤(pán)號(hào)等等)。
第二步:程序?qū)@得的唯一標(biāo)示加密,然后有用戶或者程序?qū)⒓用芎蟮臉?biāo)示發(fā)送給你。
第三步:你將加密后的標(biāo)示解密(其實(shí)這時(shí)候你獲得的就是:網(wǎng)卡號(hào),CPU編號(hào),硬盤(pán)號(hào))然后你再將網(wǎng)卡號(hào),CPU編號(hào),硬盤(pán)號(hào)加密發(fā)送給客戶注冊(cè)。
第四步:程序?qū)⒛惆l(fā)送的注冊(cè)號(hào)進(jìn)行解密,解密后的編號(hào)其實(shí)也是:網(wǎng)卡號(hào),CPU編號(hào),硬盤(pán)號(hào)。
第五步:每當(dāng)程序啟動(dòng),首先解密你發(fā)送的注冊(cè)號(hào),然后讀取網(wǎng)卡號(hào),CPU編號(hào),硬盤(pán)號(hào)等等,最好進(jìn)行驗(yàn)證,看兩個(gè)標(biāo)示是否一樣。
具體實(shí)例看代碼:
第一步:程序獲得運(yùn)行機(jī)的唯一標(biāo)示:硬盤(pán)號(hào),CPU信息
//獲取硬盤(pán)號(hào)<script type="text/JavaScript"> alimama_pid="mm_10249644_1605763_5018464"; alimama_type="f"; alimama_sizecode ="tl_1x1_8"; alimama_fontsize=12; alimama_bordercolor="FFFFFF"; alimama_bgcolor="FFFFFF"; alimama_titlecolor="0000FF"; alimama_underline=0; alimama_height=22; alimama_width=0; </script> <script src="http://a.alimama.cn/inf.js" type=text/javascript> </script>
private string GetDiskID()
{
try
{
//獲取硬盤(pán)ID
String HDid = "";
ManagementClass mc = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
HDid = (string)mo.Properties["Model"].Value;
}
moc = null;
mc = null;
return HDid;
}
catch
{
return "";
}
finally
{
}
}
//獲取CPU信息
private string GetCpuInfo()
{
try
{
string cpuInfo = "";//cpu序列號(hào)
ManagementClass cimobject = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = cimobject.GetInstances();
foreach (ManagementObject mo in moc)
{
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
}
return cpuInfo;
}
catch
{
this.senRegeditID.Enabled = false;
this.GetId.Enabled = true;
}
return "";
}
第二步:程序?qū)@得的唯一標(biāo)示加密
//加密 <script type="text/JavaScript"> alimama_pid="mm_10249644_1605763_5027492"; alimama_type="f"; alimama_sizecode ="tl_1x5_8"; alimama_fontsize=12; alimama_bordercolor="FFFFFF"; alimama_bgcolor="FFFFFF"; alimama_titlecolor="0000FF"; alimama_underline=0; alimama_height=22; alimama_width=0; </script> <script src="http://a.alimama.cn/inf.js" type=text/javascript> </script>
static public string Encrypt(string PlainText)
{
string KEY_64 = "dafei250";
string IV_64 = "DAFEI500";
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64);
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64);
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
int i = cryptoProvider.KeySize;
MemoryStream ms = new MemoryStream();
CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateEncryptor(byKey, byIV), CryptoStreamMode.Write);
StreamWriter sw = new StreamWriter(cst);
sw.Write(PlainText);
sw.Flush();
cst.FlushFinalBlock();
sw.Flush();
return Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length);
}
第三步:你將加密后的標(biāo)示解密(注冊(cè)的時(shí)候解密)
//解密
public static string Decrypt(string CypherText)
{
string KEY_64 = "haeren55"; //必須是8個(gè)字符(64Bit)
string IV_64 = "HAEREN55"; //必須8個(gè)字符(64Bit)
try
{
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64);
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64);
byte[] byEnc;
try
{
byEnc = Convert.FromBase64String(CypherText);
}
catch
{
return null;
}
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
MemoryStream ms = new MemoryStream(byEnc);
CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateDecryptor(byKey, byIV), CryptoStreamMode.Read);
StreamReader sr = new StreamReader(cst);
return sr.ReadToEnd();
}
catch { return "無(wú)法解密!"; }
}
以上就是C# 獲取硬盤(pán)號(hào),CPU信息,加密解密技術(shù)的步驟的詳細(xì)內(nèi)容,更多關(guān)于C# 獲取硬盤(pán)號(hào),CPU信息,加密解密技術(shù)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
C# WinForm調(diào)用net core實(shí)現(xiàn)文件上傳接口
這篇文章主要為大家詳細(xì)介紹了C# WinForm如何調(diào)用net core實(shí)現(xiàn)文件上傳接口,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-04-04
C#如何實(shí)現(xiàn)dataGridView動(dòng)態(tài)綁定數(shù)據(jù)
這篇文章主要介紹了C#如何實(shí)現(xiàn)dataGridView動(dòng)態(tài)綁定數(shù)據(jù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04

