Exemplo n.º 1
0
        //Checks if the evaluation date (Relative) is not expired

        #region         private bool IsInsideTimeRelative(DatosFile myFileData)

        private bool IsInsideTimeRelative(DatosFile myFileData)
        {
            bool blnReturn = false;

            try
            {
                DateTime InitiationDateFromReg;
                //Make a key for the register (using ProductID and VersionID, encrypted and based in the LicenseID
                using (CryptoString myCrypto = new CryptoString())
                {
                    string RegKeyDirectory = myCrypto.Encrypt((myFileData.ProductID + myFileData.ProductVersion),
                                                              myFileData.LicenseID);
                    string RegKeyValue = myCrypto.Encrypt(DateTime.Today.ToShortDateString(), myFileData.LicenseID);

                    //If the key exists in the register, retrive his value
                    string strInitiationDateFromReg = ReadFromRegistry(string.Empty, RegKeyDirectory);

                    //If the key not exists in the register, make one with the date of today (also encrypted)
                    if (strInitiationDateFromReg.Length == 0) //Key doesn't exist --> make a new one
                    {
                        WriteToRegistry(string.Empty, RegKeyDirectory, RegKeyValue);
                    }

                    //Compare the value in the register with today
                    strInitiationDateFromReg = ReadFromRegistry(string.Empty, RegKeyDirectory);
                    InitiationDateFromReg    =
                        DateTime.Parse(myCrypto.Decrypt(strInitiationDateFromReg, myFileData.LicenseID));
                }
                // DateTime ExpirationDate = InitiationDateFromReg.AddDays(int.Parse(myFileData.DaysToExpiration));

                if (DateTime.Today <= InitiationDateFromReg)
                {
                    blnReturn = true;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("BuscarControlar:Controlar.IsInsideTimeRelative - " + ex);
            }

            return(blnReturn);
        }
Exemplo n.º 2
0
        //Decript the Licence File

        #region         private bool LeerFile(TextReader myTextReader, ref DatosFile myFileData)

        private bool LeerFile(TextReader myTextReader, ref DatosFile myFileData)
        {
            /* File Schema:
             * File Format: spsproparts_[ProductID]_productVersion].lic
             *
             * spsProParts                          --> Always
             * http://www.spsproparts.net           --> Always
             * ProductName: productAAA              --> Product Name, doesn't have any meaning
             * ProductVersion: 1.0.0.0              --> Needs to be the same as in the name of the lic file (used internally without dots)
             * ProductID: 123456789ABCDEF           --> Needs to be the same as in the name of the lic file
             * LicenseID: 987654321QWERTY           --> IMPORTANT: needed als public key to decrypt the raw data
             * RXpTjTdBl7RP1oQqfqScDlYXQxgAYPg+m    --> Raw data
             *
             * Raw data format:
             * EngineVersion|LicenseDate|TypeLicense|EvaluationDate|EvaluationDays|MAC|IP|Domain|Client|Other
             * 1.0|20071125|mac|||112233445566|||ClientAAA||
             * EngineVersion                        --> The version of this Class. In the future, the class can change
             * LicenseDate                          --> Date of issuance of the License - yyyymmdd
             * TypeLicense                          --> can be: mac - ip - days - date - domain
             * EvaluationDate                       --> If the expiration evaluation periode is absolute - yyyymmdd
             * EvaluationDays                       --> If the expiration evaluation periode is relative - number of days
             * MAC                                  --> MAC Address to check, if TypeLicense is "mac"
             * IP                                   --> IP Address to check, if TypeLicense is "ip"
             * Domain                               --> Domain name to check, if TypeLicense is "domain"
             *  Host
             * Client                               --> Client name and other information
             * Other                                --> Reserved for other information
             * Host
             */

            bool   blnReturn = false;
            string OneLine;
            int    LineCounter = 1;

            string[] TempString;

            try
            {
                //Read each line of the File, inclusive the raw data (last line), and set it in the object
                while ((OneLine = myTextReader.ReadLine()) != null)
                {
                    //Console.WriteLine(OneLine);

                    switch (LineCounter)
                    {
                    case (1):
                        //Nothing to do --> "spsProParts"
                        break;

                    case (2):
                        //Nothing to do --> "http://www.spsrproparts.net"
                        break;

                    case (3):
                        TempString             = OneLine.Split(':');
                        myFileData.ProductName = TempString[1].Trim();
                        break;

                    case (4):
                        TempString = OneLine.Split(':');
                        myFileData.ProductVersion = TempString[1].Trim().Replace(".", string.Empty);
                        break;

                    case (5):
                        TempString           = OneLine.Split(':');
                        myFileData.ProductID = TempString[1].Trim();
                        break;

                    case (6):
                        TempString           = OneLine.Split(':');
                        myFileData.LicenseID = TempString[1].Trim();
                        break;

                    case (7):
                        myFileData.RawData = OneLine;
                        break;

                    default:
                        break;
                    }
                    LineCounter++;
                }
                myTextReader.Close();

                string RawLine;
                //Read the values of the encrypted last line, and set it in the object
                using (CryptoString myCryptoString = new CryptoString())
                {
                    RawLine = myCryptoString.Decrypt(myFileData.RawData, myFileData.LicenseID);
                    //string RawLine = myCryptoString.Encrypt("1.0|20071125|days||1|11223344556677|||clientAA||", myFileData.LicenseID);
                    //Console.WriteLine(RawLine);
                }
                TempString = RawLine.Split('|');
                myFileData.LicenseEngineVersion = TempString[0].Trim();
                myFileData.LicenseDate          = TempString[1].Trim();
                //Type Licenses can be: mac - ip - days - date - domain
                switch (TempString[2].Trim().ToLower())
                {
                case ("mac"):
                    myFileData.LicenseSort = DatosFile.TypeLicense.MAC;
                    break;

                case ("ip"):
                    myFileData.LicenseSort = DatosFile.TypeLicense.IP;
                    break;

                case ("days"):
                    myFileData.LicenseSort = DatosFile.TypeLicense.EvaluationDays;
                    break;

                case ("date"):
                    myFileData.LicenseSort = DatosFile.TypeLicense.EvaluationDate;
                    break;

                case ("domain"):
                    myFileData.LicenseSort = DatosFile.TypeLicense.Domain;
                    break;

                case ("host"):
                    myFileData.LicenseSort = DatosFile.TypeLicense.Host;
                    break;

                default:
                    break;
                }
                myFileData.DateExpiration   = TempString[3].Trim();
                myFileData.DaysToExpiration = TempString[4].Trim();
                myFileData.MacAddress       = TempString[5].Trim();
                myFileData.IpAddress        = TempString[6].Trim();
                myFileData.DomainName       = TempString[7].Trim();
                myFileData.HostName         = TempString[8].Trim();
                myFileData.ClientName       = TempString[9].Trim();
                myFileData.OtherInformation = TempString[10].Trim();

                blnReturn = true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("BuscarControlar:Controlar.LeerFile - " + ex);
            }

            return(blnReturn);
        }