Esempio n. 1
0
        public static bool Generate(string filename, string macAddress, DateTime expiration, int clientLicenseCount, string disabledFeatureList)
        {
            DateTime installDate = DateTime.Now;

            string output = String.Concat(macAddress, "$", installDate.ToString(), "$", expiration.ToString(), "$", clientLicenseCount.ToString(), "$", disabledFeatureList, "$");

            Random rand = new Random(DateTime.Now.Second);

            for (int i = 0; i < 1024; i++)
            {
                char ch = (char)rand.Next('0', '9');
                output = String.Concat(output, ch);
            }

            Int64 checksum = 0;

            for (int i = 0; i < output.Length; i++)
            {
                checksum += Convert.ToInt64(Char.GetNumericValue(output[i]));
            }

            output = String.Concat(checksum.ToString(), "$", output);

            output = MOG_Encryption.Encrypt(output);
            return(DosUtils.FileWrite(filename, output));
        }
Esempio n. 2
0
        public bool Load()
        {
            try
            {
                if (DosUtils.FileExistFast(mFilename))
                {
                    string contents = DosUtils.FileRead(mFilename);
                    if (contents.Length > 0)
                    {
                        contents = MOG_Encryption.Decrypt(contents);

                        string[] parts = contents.Split("$".ToCharArray());

                        if (parts.Length >= 5)
                        {
                            Int64 savedChecksum = Int64.Parse(parts[0]);
                            mMacAddress         = parts[1];
                            mInstallDate        = DateTime.Parse(parts[2]);
                            mExpireDate         = DateTime.Parse(parts[3]);
                            mClientLicenseCount = Int32.Parse(parts[4]);
                            if (parts.Length >= 6)
                            {
                                mDisabledFeatureList = parts[5];
                            }

                            //generate a new checksum and compare it with the one we saved out
                            contents = contents.Substring(parts[0].Length + 1);
                            Int64 checksum = 0;
                            for (int i = 0; i < contents.Length; i++)
                            {
                                checksum += Convert.ToInt64(Char.GetNumericValue(contents[i]));
                            }

                            if (savedChecksum == checksum)
                            {
                                mIsLoaded = true;
                            }
                        }
                    }
                }
            }
            catch
            {
                mIsLoaded = false;
            }

            return(mIsLoaded);
        }