国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

基于C#的軟件加密、授權(quán)與注冊(cè)

這篇具有很好參考價(jià)值的文章主要介紹了基于C#的軟件加密、授權(quán)與注冊(cè)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

??本文介紹了基于 本機(jī)特征信息(如CPU、主板、BIOS和MAC等) 的軟件加密、授權(quán)與注冊(cè)方法,并分享了 示例程序完整源代碼。


1 加密、授權(quán)與注冊(cè)

??軟件的加密、授權(quán)與注冊(cè)流程如下:

基于C#的軟件加密、授權(quán)與注冊(cè)

2 本機(jī)特征信息

??本機(jī)特征信息主要包括:①CPU信息、②主板序列號(hào)、③BIOS信息、④MAC地址,基于C#獲取代碼如下:

using System;
using System.Management;
using System.Net.NetworkInformation;
using Microsoft.Win32;

namespace RWRegister
{
    public class Computer
    {
        public static string ComputerInfo()
        {
            string info = string.Empty;
            string cpu = GetCPUInfo();
            string baseBoard = GetBaseBoardInfo();
            string bios = GetBIOSInfo();
            string mac = GetMACInfo();
            info = string.Concat(cpu, baseBoard, bios, mac);
            return info;
        }

        private static string GetCPUInfo()
        {
            string info = string.Empty;
            info = GetHardWareInfo("Win32_Processor", "ProcessorId");
            return info;
        }

        private static string GetBaseBoardInfo()
        {
            string info = string.Empty;
            info = GetHardWareInfo("Win32_BaseBoard", "SerialNumber");
            return info;
        }

        private static string GetBIOSInfo()
        {
            string info = string.Empty;
            info = GetHardWareInfo("Win32_BIOS", "SerialNumber");
            return info;
        }

        private static string GetMACInfo()
        {
            string info = string.Empty;
            info = GetMacAddressByNetwork();
            return info;
        }

        private static string GetHardWareInfo(string typePath, string Key)
        {
            try
            {
                ManagementClass mageClass = new ManagementClass(typePath);
                ManagementObjectCollection mageObjectColl = mageClass.GetInstances();
                PropertyDataCollection Properties = mageClass.Properties;
                foreach (PropertyData property in Properties)
                {
                    if (property.Name == Key)
                    {
                        foreach (ManagementObject mageObject in mageObjectColl)
                        {
                            return mageObject.Properties[property.Name].Value.ToString();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return string.Empty;
        }

        private static string GetMacAddressByNetwork()
        {
            string Key = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\";
            string macAddress = string.Empty;
            try
            {
                NetworkInterface[] Nics = NetworkInterface.GetAllNetworkInterfaces();
                foreach (NetworkInterface adapter in Nics)
                {
                    if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet && adapter.GetPhysicalAddress().ToString().Length != 0)
                    {
                        string fRegistryKey = Key + adapter.Id + "\\Connection";
                        RegistryKey rKey = Registry.LocalMachine.OpenSubKey(fRegistryKey, false);
                        if (rKey != null)
                        {
                            string fPnpInstanceID = rKey.GetValue("PnpInstanceID", "").ToString();
                            int fMediaSubType = Convert.ToInt32(rKey.GetValue("MediaSubType", 0));
                            if (fPnpInstanceID.Length > 3 && fPnpInstanceID.Substring(0, 3) == "PCI")
                            {
                                macAddress = adapter.GetPhysicalAddress().ToString();
                                for (int i = 1; i < 6; i++)
                                {
                                    macAddress = macAddress.Insert(3 * i - 1, ":");
                                }
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return macAddress;
        }
    }
}

3 加密與解密算法

??加密方法包括:①秘鑰加密(KeyA+keyB)、②MD5加密。基于C#的加密與解密算法如下:

using System;
using System.Security.Cryptography;
using System.Text;
using System.IO;

namespace RWRegister
{
    public enum CryptoKey
    {
        KeyA, KeyB
    }

    public class Encryption
    {
        private string KeyA = "Sgg***";
        private string KeyB = "Qing***";
        private string MD5strBegin = "C++***";
        private string MD5strEnd = "Matlab***";
        private string ExecuteKey = string.Empty;

        public Encryption()
        {
            InitKey();//KeyA
        }

        public Encryption(CryptoKey Key)
        {
            InitKey(Key);//Custom
        }

        private void InitKey(CryptoKey Key = CryptoKey.KeyA)
        {
            switch (Key)
            {
                case CryptoKey.KeyA:
                    ExecuteKey = KeyA;
                    break;
                case CryptoKey.KeyB:
                    ExecuteKey = KeyB;
                    break;
            }
        }

        public string EncryptOfKey(string str)
        {
            return Encrypt(str, ExecuteKey);
        }

        public string DecryptOfKey(string str)
        {
            return Decrypt(str, ExecuteKey);
        }

        public string EncryptOfMD5(string str)
        {
            str = string.Concat(MD5strBegin, str, MD5strEnd);//trim
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] fromdata = Encoding.Unicode.GetBytes(str);
            byte[] todata = md5.ComputeHash(fromdata);
            string MD5str = string.Empty;
            foreach (var data in todata)
            {
                MD5str += data.ToString("x2");
            }
            return MD5str;
        }

        private string Encrypt(string str, string sKey)
        {
            DESCryptoServiceProvider DESCsp = new DESCryptoServiceProvider();
            byte[] InputBytes = Encoding.Default.GetBytes(str);
            DESCsp.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
            DESCsp.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, DESCsp.CreateEncryptor(), CryptoStreamMode.Write);
            cs.Write(InputBytes, 0, InputBytes.Length);
            cs.FlushFinalBlock();
            StringBuilder builder = new StringBuilder();
            foreach (byte b in ms.ToArray())
            {
                builder.AppendFormat("{0:X2}", b);
            }
            builder.ToString();
            return builder.ToString();
        }

        private string Decrypt(string pToDecrypt, string sKey)
        {
            DESCryptoServiceProvider DESCsp = new DESCryptoServiceProvider();
            byte[] InputBytes = new byte[pToDecrypt.Length / 2];
            for (int x = 0; x < pToDecrypt.Length / 2; x++)
            {
                int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
                InputBytes[x] = (byte)i;
            }
            DESCsp.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
            DESCsp.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, DESCsp.CreateDecryptor(), CryptoStreamMode.Write);
            cs.Write(InputBytes, 0, InputBytes.Length);
            cs.FlushFinalBlock();
            return Encoding.Default.GetString(ms.ToArray());
        }
    }
}

4 軟件授權(quán)檢測(cè)

??軟件授權(quán)檢測(cè)代碼如下:

using System;
using System.Collections.Generic;
using System.IO;

namespace RWRegister
{
    public class Register
    {
        public static string CryptographFile = "Cryptograph.Key";
        public static string LicenseFile = "license.Key";

        public static void WriteCryptographFile(string info)
        {
            WriteFile(info, CryptographFile);
        }

        public static void WriteLicenseFile(string info)
        {
            WriteFile(info, LicenseFile);
        }

        public static string ReadCryptographFile()
        {
            return ReadFile(CryptographFile);
        }

        public static string ReadLicenseFile()
        {
            return ReadFile(LicenseFile);
        }

        public static bool ExistCryptographFile()
        {
            return File.Exists(CryptographFile);
        }

        public static bool ExistLicenseFile()
        {
            return File.Exists(LicenseFile);
        }

        private static void WriteFile(string info, string fileName)
        {
            try
            {
                using (StreamWriter writer = new StreamWriter(fileName, false))
                {
                    writer.Write(info);
                    writer.Close();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        private static string ReadFile(string fileName)
        {
            string info = string.Empty;
            try
            {
                using (StreamReader reader = new StreamReader(fileName))
                {
                    info = reader.ReadToEnd();
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return info;
        }

        public static bool CheckRegister()
        {
            //MD5 Cryptograph of Computer information
            string CryptoInfo = Computer.ComputerInfo();
            Encryption encryptor = new Encryption(CryptoKey.KeyA);
            CryptoInfo = encryptor.EncryptOfKey(CryptoInfo);//KeyA
            string MD5CryptoInfo = encryptor.EncryptOfMD5(CryptoInfo);//MD5
            //judge the exist of Cryptograph file
            if (!ExistCryptographFile() || CryptoInfo != ReadCryptographFile())
            {
                WriteCryptographFile(CryptoInfo);
            }
            //judge the exist of License file
            if (!ExistLicenseFile())
            {
                return false;
            }
            //MD5 Cryptograph of License file
            string MD5License = ReadLicenseFile();
            encryptor = new Encryption(CryptoKey.KeyB);
            MD5License = encryptor.DecryptOfKey(MD5License);//KeyB
            if (MD5License == MD5CryptoInfo)//two md5 clash
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}

5 示例程序

5.1 界面設(shè)計(jì)

??示例程序界面設(shè)計(jì)如下圖,包括:① “文件(F)” 菜單(包含“數(shù)據(jù)”、“退出”子菜單);② “幫助(H)” 菜單(包含“幫助文檔”、“軟件注冊(cè)”子菜單)。軟件開啟時(shí),將自動(dòng)檢測(cè)授權(quán)情況,若未授權(quán)僅有20秒的試用時(shí)間(20秒后將禁用軟件);若軟件未授權(quán),可按 “幫助”->“軟件注冊(cè)”步驟 進(jìn)行授權(quán)。
基于C#的軟件加密、授權(quán)與注冊(cè)

5.2 模塊代碼

??模塊代碼如下,包括窗體載入、軟件注冊(cè)等。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;

namespace RWRegister
{
    public partial class softWare : Form
    {
        public static bool registerState = false;
        private const int trialRunTime = 20;//seconds

        public softWare()
        {
            InitializeComponent();
        }

        private void softWare_Load(object sender, EventArgs e)
        {
            MyTimer.Enabled = true;
            MyTimer.Interval = 1000;
            toolStripSLTime.Text = "";

            //軟件授權(quán)檢測(cè)
            if (Register.CheckRegister())
            {
                registerState = true;
            }
            else
            {
                softWareTrialRun();
            }
        }

        /// <summary>
        /// 試運(yùn)行軟件(后臺(tái)線程)
        /// </summary>
        private void softWareTrialRun()
        {
            Thread threadClose = new Thread(softWareClose);
            threadClose.IsBackground = true;//后臺(tái)
            threadClose.Start();
        }

        private void softWareClose()
        {
            int count = 0;
            while (!registerState && count < trialRunTime)
            {
                if (registerState)
                {
                    return;
                }
                Thread.Sleep(1000);//1 sec
                count += 1;
            }
            if (registerState)
            {
                return;
            }
            else
            {
                Environment.Exit(0);
            }
        }

        private void toolStripMExit_Click(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }

        private void toolStripMRegister_Click(object sender, EventArgs e)
        {
            if (registerState)
            {
                MessageBox.Show("軟件已注冊(cè)授權(quán)!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            string fileName = string.Empty;
            ofdLicense.Title = "打開許可文件";
            ofdLicense.Filter = "許可文件(*.Key)|*.Key";
            if (ofdLicense.ShowDialog() == DialogResult.OK)
            {
                fileName = ofdLicense.FileName;
            }
            else
            {
                return;
            }
            string localFileName = string.Concat(
               Environment.CurrentDirectory,
               Path.DirectorySeparatorChar,
               Register.LicenseFile);
            if (fileName != localFileName)
                File.Copy(fileName, localFileName, true);
            if (Register.CheckRegister())
            {
                registerState = true;
                MessageBox.Show("注冊(cè)成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("許可文件非法!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void MyTimer_Tick(object sender, EventArgs e)
        {
            toolStripSLTime.Text = "本地時(shí)間:" + DateTime.Now.ToString();//北京時(shí)間
        }
    }
}

5.3 完整代碼下載

??文檔資源:基于C#的軟件加密、授權(quán)與注冊(cè) 貨真價(jià)實(shí)、童叟無欺,歡迎指導(dǎo)交流學(xué)習(xí)!文章來源地址http://www.zghlxwxcb.cn/news/detail-404914.html

到了這里,關(guān)于基于C#的軟件加密、授權(quán)與注冊(cè)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 電腦文件加密軟件哪個(gè)最好用:試試文件加密軟件排行榜第一的EaseUS LockMyFile吧 | 軍事級(jí)加密你值得擁有!??!

    電腦文件加密軟件哪個(gè)最好用:試試文件加密軟件排行榜第一的EaseUS LockMyFile吧 | 軍事級(jí)加密你值得擁有!??!

    ? ? ? ? EaseUS LockMyFile 是一款出色且安全可靠的軍事級(jí)電腦文件加密管理軟件,也叫 易我文件加密軟件 ,擁有文件隱藏、文件加鎖、文件保護(hù)、讀寫監(jiān)控、安全刪除等諸多實(shí)用功能,能幫助大家鎖定和隱藏閃存驅(qū)動(dòng)器、外部USB 驅(qū)動(dòng)器、內(nèi)部硬盤驅(qū)動(dòng)器以及局域網(wǎng)中其他計(jì)算

    2024年01月25日
    瀏覽(18)
  • 如何選擇源代碼加密軟件

    比較內(nèi)容 安全容器(SDC沙盒) DLP 文檔加密 云桌面 代表廠家 *信達(dá) 賣咖啡、賽門貼科 億*通、IP噶德、*盾、*途 四杰、深*服 設(shè)計(jì)理念 以隔離容器加準(zhǔn)入技術(shù)為基礎(chǔ),構(gòu)建只進(jìn)不出,要出需走審批的數(shù)據(jù)安全環(huán)境,環(huán)境內(nèi)數(shù)據(jù)一視同仁,不區(qū)分文件格式,一律保護(hù)。 以內(nèi)容識(shí)別

    2024年02月07日
    瀏覽(94)
  • 加密狗軟件有什么作用?

    加密狗軟件有什么作用?

    加密狗軟件是一種用于加密和保護(hù)計(jì)算機(jī)軟件和數(shù)據(jù)的安全設(shè)備。它通常是一個(gè)硬件設(shè)備,可以通過USB接口連接到計(jì)算機(jī)上。加密狗軟件的作用主要體現(xiàn)在以下幾個(gè)方面: 軟件保護(hù):加密狗軟件可以對(duì)軟件進(jìn)行加密和授權(quán),防止未經(jīng)授權(quán)的用戶復(fù)制、修改或傳播軟件。只有插

    2024年02月09日
    瀏覽(17)
  • 怎么加密文件夾才更安全?安全文件夾加密軟件推薦

    怎么加密文件夾才更安全?安全文件夾加密軟件推薦

    文件夾加密可以讓其中數(shù)據(jù)更加安全,但并非所有加密方式都能夠提高極高的安全強(qiáng)度。那么,怎么加密文件夾才更安全呢?下面我們就來了解一下那些安全的文件夾加密軟件。 如果要評(píng)選最安全的文件夾加密軟件,那么 文件夾加密超級(jí)大師 一定會(huì)名列榜首。 針對(duì)文件夾加

    2024年02月14日
    瀏覽(26)
  • 企業(yè)電腦文件加密系統(tǒng) / 防泄密軟件——「天銳綠盾」

    企業(yè)電腦文件加密系統(tǒng) / 防泄密軟件——「天銳綠盾」

    「天銳綠盾」是一種公司文件加密系統(tǒng),旨在保護(hù)公司內(nèi)網(wǎng)數(shù)據(jù)安全,防止信息泄露。該系統(tǒng)由硬件和軟件組成,其中包括服務(wù)端程序、控制臺(tái)程序和終端程序。 PC訪問地址: isite.baidu.com/site/wjz012xr/2eae091d-1b97-4276-90bc-6757c5dfedee 服務(wù)端程序需要運(yùn)行在不關(guān)機(jī)的服務(wù)器電腦上,

    2024年02月10日
    瀏覽(23)
  • 公司內(nèi)部傳文件怎么安全——「用綠盾透明加密軟件」

    公司內(nèi)部傳文件怎么安全——「用綠盾透明加密軟件」

    為保證公司內(nèi)部文件傳遞的安全性,可以使用天銳綠盾透明加密軟件來進(jìn)行保護(hù)。以下是具體的操作步驟: 在公司內(nèi)部部署天銳綠盾加密軟件,確保需要傳遞的文件都能受到加密保護(hù)。 在員工的工作電腦上安裝天銳綠盾客戶端,并設(shè)置好相關(guān)的加密規(guī)則。例如,可以設(shè)置對(duì)

    2024年02月21日
    瀏覽(33)
  • 信息安全技術(shù)—實(shí)驗(yàn)三—PGP郵件加密軟件的使用

    信息安全技術(shù)—實(shí)驗(yàn)三—PGP郵件加密軟件的使用

    一、實(shí)驗(yàn)?zāi)康募耙?????????1.熟悉公開密鑰密碼體制,了解證書的基本原理,熟悉數(shù)字簽名; ????????2.熟練使用PGP的基本操作,能對(duì)郵件或傳輸文檔進(jìn)行加密; 二、實(shí)驗(yàn)內(nèi)容 ????????1創(chuàng)建一私鑰和公鑰對(duì) ????????使用PGPtray之前,需要用PGPkeys生成一對(duì)密鑰,

    2024年02月06日
    瀏覽(20)
  • 加密解密軟件VMProtect教程(四):準(zhǔn)備項(xiàng)目之使用標(biāo)記

    VMProtect 是保護(hù)應(yīng)用程序代碼免遭分析和破解的可靠工具,但只有在正確構(gòu)建應(yīng)用程序內(nèi)保護(hù)機(jī)制并且沒有可能破壞整個(gè)保護(hù)的典型錯(cuò)誤的情況下才能最有效地使用。 為了保護(hù)代碼的各個(gè)片段和字符串常量,您可以在應(yīng)用程序的源代碼中插入特殊標(biāo)記。標(biāo)記是對(duì)從外部庫導(dǎo)入

    2024年02月05日
    瀏覽(22)
  • 利用RSA加密打造強(qiáng)大License驗(yàn)證,確保軟件正版合法運(yùn)行

    利用RSA加密打造強(qiáng)大License驗(yàn)證,確保軟件正版合法運(yùn)行

    ? 概述: C#軟件開發(fā)中,License扮演著確保軟件合法使用的重要角色。采用RSA非對(duì)稱加密方案,服務(wù)端生成帶簽名的License,客戶端驗(yàn)證其有效性,從而實(shí)現(xiàn)對(duì)軟件的授權(quán)與安全保障。 License(許可證)在C#軟件開發(fā)中被廣泛應(yīng)用,以確保軟件在合法授權(quán)的環(huán)境中運(yùn)行。常見場(chǎng)景

    2024年02月19日
    瀏覽(24)
  • 6個(gè)免費(fèi)好用的 PDF 文件加密軟件 [Windows & Mac]

    6個(gè)免費(fèi)好用的 PDF 文件加密軟件 [Windows & Mac]

    加密 PDF 文件使您能夠保護(hù)它們免受未經(jīng)授權(quán)的訪問。當(dāng)重要信息處于危險(xiǎn)之中時(shí),黑客可以訪問電子文檔。 考慮到它們很容易被黑客入侵,您需要迅速采取行動(dòng)。避免這種情況的方法之一是使用更適合您需要的 PDF 加密軟件。 有很多選項(xiàng)可供選擇,因此請(qǐng)務(wù)必查看我的建議

    2024年01月18日
    瀏覽(20)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包