zoukankan      html  css  js  c++  java
  • C#获取CPU与网卡硬盘序列号及Base64和DES加密解密操作类 be

     public class RegisterHelp
        {
            /// <summary>
            /// CPU
            /// </summary>
            /// <returns></returns>
            public string GetCpu()
            {
                string strCpu = null;
                ManagementClass myCpu = new ManagementClass("win32_Processor");
                ManagementObjectCollection myCpuConnection = myCpu.GetInstances();
                foreach (ManagementObject myObject in myCpuConnection)
                {
                    strCpu = myObject.Properties["Processorid"].Value.ToString();
                    break;
                }
                return strCpu;
            }
    
            /// <summary>
            /// 网卡
            /// </summary>
            /// <returns></returns>
            public string GetMacAddress()
            {
                try
                {
                    string mac = "";
                    ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
                    ManagementObjectCollection moc = mc.GetInstances();
                    foreach (ManagementObject mo in moc)
                    {
                        if ((bool)mo["IPEnabled"] == true)
                        {
                            mac = mo["MacAddress"].ToString();
                            break;
                        }
                    }
                    moc = null;
                    mc = null;
                    return mac;
                }
                catch
                {
                    return "unknow";
                }
                finally
                {
                }
    
            }
    
            /// <summary>
            /// 硬盘
            /// </summary>
            /// <returns></returns>
            public string GetDiskID()
            {
                try
                {
                    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 "unknow";
                }
                finally
                {
                }
    
            }
    
    
            /// <summary>
            /// Base64解密
            /// </summary>
            /// <param name="input">需要解密的字符串</param>
            /// <returns></returns>
            public string Base64Decrypt(string input)
            {
                return Base64Decrypt(input, new UTF8Encoding());
            }
    
            /// <summary>
            /// DES解密
            /// </summary>
            /// <param name="data">解密数据</param>
            /// <param name="key">8位字符的密钥字符串(需要和加密时相同)</param>
            /// <param name="iv">8位字符的初始化向量字符串(需要和加密时相同)</param>
            /// <returns></returns>
            public string DESDecrypt(string data, string key, string iv)
            {
                byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(key);
                byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(iv);
    
                byte[] byEnc;
                try
                {
                    byEnc = Convert.FromBase64String(data);
                }
                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();
            }
    
            /// <summary>
            /// Base64解密
            /// </summary>
            /// <param name="input">需要解密的字符串</param>
            /// <param name="encode">字符的编码</param>
            /// <returns></returns>
            public string Base64Decrypt(string input, Encoding encode)
            {
                return encode.GetString(Convert.FromBase64String(input));
            }
    
    
            public string Decode(string str)
            {
                string dtext = "";
                for (int i = 0; i < str.Length; i++)
                {
                    dtext = dtext + (char)(str[i] - 10 + 1 * 2);
                }
                return dtext;
            }
    
    
            public string GetText(RichTextBox richTextBox)
            {
                TextRange textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
                return textRange.Text;
            }
        }
  • 相关阅读:
    《Java技术》第七次作业计科1501赵健宇
    《Java技术》第六次作业计科1501赵健宇
    《Java技术》第五次作业计科1501赵健宇
    《Java技术》第四次作业计科1501赵健宇
    《Java技术》第三次作业计科1501赵健宇
    整站灰度CSS 代码
    HTML中input输入框禁止复制粘贴剪切自动完成
    无法嵌入互操作类型“ApplicationClass”。请改用适用的接口
    添加右键VSCode打开
    async & await 异步编程小示例,一看就懂
  • 原文地址:https://www.cnblogs.com/CityOfThousandFires/p/13268116.html
Copyright © 2011-2022 走看看