コード例 #1
0
ファイル: SystemUtils.cs プロジェクト: zbxpcq/Afx.Lib
        private static string GetMachineID(string appId, string hdInfo)
        {
            string id = null;

            try
            {
                using (var regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(REG_PATH))
                {
                    if (regkey != null)
                    {
                        string reg_hdInfo = (string)regkey.GetValue(HD_INFO_KEY, null);
                        if (!string.IsNullOrEmpty(reg_hdInfo))
                        {
                            reg_hdInfo = DesUtils.Decrypt(reg_hdInfo, MyDevice_DES_KEY);
                        }
                        if (reg_hdInfo == hdInfo)
                        {
                            id = (string)regkey.GetValue(appId, null);
                            if (!string.IsNullOrEmpty(id))
                            {
                                string deskey = hdInfo.Substring(4, 4) + hdInfo.Substring(12, 4);
                                id = DesUtils.Decrypt(id, deskey);
                            }
                        }
                        regkey.Close();
                    }
                }
            }
            catch { }

            return(id);
        }
コード例 #2
0
ファイル: SystemUtils.cs プロジェクト: zbxpcq/Afx.Lib
        private static void SetMachineID(string appId, string id, string hdInfo)
        {
            if (!string.IsNullOrEmpty(id))
            {
                try
                {
                    using (var regkey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(REG_PATH))
                    {
                        string s = DesUtils.Encrypt(hdInfo, MyDevice_DES_KEY);
                        regkey.SetValue(HD_INFO_KEY, s, Microsoft.Win32.RegistryValueKind.String);

                        string deskey = hdInfo.Substring(4, 4) + hdInfo.Substring(12, 4);
                        s = DesUtils.Encrypt(id, deskey);
                        regkey.SetValue(appId, s, Microsoft.Win32.RegistryValueKind.String);

                        regkey.Flush();
                        regkey.Close();
                    }
                }
                catch { }
            }
        }