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#如何Task執(zhí)行任務(wù),等待任務(wù)完成
這篇文章主要介紹了C#如何Task執(zhí)行任務(wù),等待任務(wù)完成,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-06-06
c# Bitmap轉(zhuǎn)bitmapImage高效方法
本文主要介紹了c# Bitmap轉(zhuǎn)bitmapImage高效方法,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11
.NET使用IResourceMonitor實(shí)現(xiàn)獲取資源信息
在 Microsoft.Extensions.Diagnostics.ResourceMonitoring 包提供了一系列定制 API,專(zhuān)用于監(jiān)視 .NET 應(yīng)用程序的資源利用率,本文將利用IResourceMonitor來(lái)實(shí)現(xiàn)獲取資源狀態(tài)信息,感興趣的可以了解下2024-01-01
C# Form自定義光標(biāo)的簡(jiǎn)單實(shí)現(xiàn)
這篇文章主要介紹了C# Form自定義光標(biāo)的簡(jiǎn)單實(shí)現(xiàn),有需要的朋友可以參考一下2014-01-01
C#中String和StringBuilder的簡(jiǎn)介與區(qū)別
今天小編就為大家分享一篇關(guān)于C#中String和StringBuilder的簡(jiǎn)介與區(qū)別,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-10-10
Unity UI實(shí)現(xiàn)循環(huán)播放序列圖
這篇文章主要為大家詳細(xì)介紹了Unity UI實(shí)現(xiàn)循環(huán)播放序列圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08
C#實(shí)現(xiàn)對(duì)象XML序列化的方法
這篇文章主要介紹了C#實(shí)現(xiàn)對(duì)象XML序列化的方法,是C#常見(jiàn)的實(shí)用技巧,需要的朋友可以參考下2014-11-11

