/// <summary>
        /// Checks that they key has not expired (i.e. the expire date has not been reached).
        /// </summary>
        /// <param name="checkWithInternetTime">If set to true, we will also check that the local
        /// time (on the client computer) has not been changed (using SKM.TimeCheck).
        /// </param>
        /// <returns>A key information object if the condition is satisfied. Null otherwise.</returns>
        public static LicenseKey HasNotExpired(this LicenseKey licenseKey, bool checkWithInternetTime = false)
        {
            if (licenseKey != null)
            {
                TimeSpan ts = licenseKey.Expires - DateTime.UtcNow;

                if (ts.Days >= 0)
                {
                    if (checkWithInternetTime && SKGL.SKM.TimeCheck())
                    {
                        return(null);
                    }
                    return(licenseKey);
                }
            }
            return(null);
        }
Example #2
0
        /// <summary>
        /// Checks so that the machine code corresponds to the machine code of this computer.
        /// </summary>
        /// <param name="hashFunction">A hash function used to hash the current computer's parameters.</param>
        /// <returns></returns>
        public static LicenseKey IsOnRightMachine(this LicenseKey licenseKey, Func <string, string> hashFunction)
        {
            if (licenseKey != null && licenseKey.ActivatedMachines != null)
            {
                var mc = SKGL.SKM.getMachineCode(hashFunction);

                foreach (var machine in licenseKey.ActivatedMachines.Where(x => x.Mid != null))
                {
                    // if we find a machine code that corresponds to that of this machine -> success.
                    if (machine.Mid.Equals(mc))
                    {
                        return(licenseKey);
                    }
                }
            }
            return(null);
        }
        /// <summary>
        /// Sets the <see cref="IntValue"/> to a new value (in SKM Platform).
        /// </summary>
        /// <param name="token">The access token. Read more at https://serialkeymanager.com/docs/api/v3/Auth </param>
        /// <param name="value">The new int value</param>
        /// <param name="licenseKey">The license key we should associate with this data object.</param>
        /// <remarks>Note: for more details, please see
        /// <a href="https://serialkeymanager.com/docs/api/v3/SetIntValue">https://serialkeymanager.com/docs/api/v3/SetIntValue</a> <br/>
        /// Note also: Integer overflows are not allowed. If you attempt to assign an int value that is beyond the limits of an int32, zero will be assigned to the data object's IntValue.</remarks>
        /// <returns>Returns <see cref="ListOfDataObjectsResult"/> or null.</returns>
        public bool SetIntValue(string token, int value, LicenseKey licenseKey)
        {
            var parameters = new ChangeIntValueToKeyModel
            {
                ProductId = licenseKey.ProductId,
                Key       = licenseKey.Key,
                Id        = Id,
                IntValue  = value
            };

            var result = Data.SetIntValue(token, parameters);

            if (result != null && result.Result == ResultType.Success)
            {
                IntValue = value;
                return(true);
            }
            return(false);
        }
Example #4
0
        /// <summary>
        /// Checks that this object has a valid signature, which means that the content has not been altered
        /// after that it was generated by Serial Key Manager.
        /// </summary>
        /// <param name="rsaPublicKey">The public key (RSA). It can be found here: https://serialkeymanager.com/User/Security </param>
        /// <param name="signatureExpirationInterval">If the license key was signed,
        /// this method will check so that no more than "signatureExpirationInterval" days have passed since the last activation.
        /// </param>
        /// <returns>A key information object if the condition is satisfied. Null otherwise.</returns>
        public static LicenseKey HasValidSignature(this LicenseKey licenseKey, string rsaPublicKey, int?signatureExpirationInterval)
        {
            if (licenseKey != null)
            {
                if (IsLicenceseKeyGenuine(licenseKey, rsaPublicKey))
                {
                    if (signatureExpirationInterval.HasValue)
                    {
                        TimeSpan ts = DateTime.Today - licenseKey.SignDate;
                        if (ts.Days >= signatureExpirationInterval.Value)
                        {
                            return(null);
                        }
                    }

                    return(licenseKey);
                }
            }
            return(null);
        }
Example #5
0
        /// <summary>
        /// Loads the <see cref="LicenseKey"/> object from a file.
        /// </summary>
        /// <param name="file">The entire path including file name, i.e. c:\folder\file.txt</param>
        /// <remarks>The current object will not be affected. Instead,
        /// you need to assign it manually, eg. licenseKey = licenseKey.LoadFromFile().</remarks>
        /// <returns>Returns the original object if successful. Null otherwise.</returns>
        public static LicenseKey LoadFromFile(this LicenseKey licenseKey, string file)
        {
            System.IO.StreamReader sr = null;
            LicenseKey             ki = null;

            try
            {
                sr = new System.IO.StreamReader(file);
                ki = Newtonsoft.Json.JsonConvert.DeserializeObject <LicenseKey>(sr.ReadToEnd());
            }
            catch { }
            finally
            {
                if (sr != null)
                {
                    sr.Dispose();
                }
            }

            return(ki);
        }
Example #6
0
        /// <summary>
        /// Loads the <see cref="LicenseKey"/> object from a file.
        /// </summary>
        /// <param name="file">The entire path including file name, i.e. c:\folder\file.txt</param>
        /// <remarks>The current object will not be affected. Instead,
        /// you need to assign it manually, eg. licenseKey = licenseKey.LoadFromFile().</remarks>
        /// <returns>Returns the original object if successful. Null otherwise.</returns>
        public static LicenseKey LoadFromFile(this LicenseKey licenseKey, string file = "licensekey.skm", string RSAPubKey = null)
        {
            System.IO.StreamReader sr = null;
            LicenseKey             ki = null;

            try
            {
                sr = new System.IO.StreamReader(file);
                ki = ki.LoadFromString(RSAPubKey, sr.ReadToEnd());
            }
            catch { }
            finally
            {
                if (sr != null)
                {
                    sr.Dispose();
                }
            }

            return(ki);
        }
        /// <summary>
        /// Decrements the <see cref="IntValue"/> by a given amount. (in SKM Platform).
        /// </summary>
        /// <param name="token">The access token. Read more at https://serialkeymanager.com/docs/api/v3/Auth </param>
        /// <param name="decrementValue">The number we should decrement by.</param>
        /// <param name="enableBound">
        /// If set to true, it will be possible to specify an lower bound.
        /// (for Decrement Int Value) For example, if you set the <paramref name="lowerBound"/> parameter (below) to 0,
        /// you will be able to decrement the int value until you reach zero (inclusive).
        /// Once the lower bound is reached, an error will be thrown.
        /// </param>
        /// <param name="lowerBound">The upper bound. It only works if <paramref name="enableBound"/> is set to true.</param>
        /// <param name="licenseKey">The license key we should associate with this data object.</param>
        /// <remarks>Note: for more details, please see
        /// <a href="https://serialkeymanager.com/docs/api/v3/IncrementIntValue">https://serialkeymanager.com/docs/api/v3/IncrementIntValue</a> <br/>
        /// </remarks>
        /// <returns>Returns true if successful or false otherwise.</returns>
        public bool DecrementIntValue(string token, int decrementValue, LicenseKey licenseKey, bool enableBound = false, int lowerBound = 0)
        {
            var parameters = new ChangeIntValueToKeyModel
            {
                ProductId   = licenseKey.ProductId,
                Key         = licenseKey.Key,
                Id          = Id,
                IntValue    = decrementValue,
                EnableBound = enableBound,
                Bound       = lowerBound
            };

            var result = Data.DecrementIntValue(token, parameters);

            if (result != null && result.Result == ResultType.Success)
            {
                IntValue -= decrementValue;
                return(true);
            }
            return(false);
        }
Example #8
0
        internal static void SetFeatureByNumber(this LicenseKey licenseKey, int i, bool value)
        {
            switch (i)
            {
            case 1:
                licenseKey.F1 = value;
                break;

            case 2:
                licenseKey.F2 = value;
                break;

            case 3:
                licenseKey.F3 = value;
                break;

            case 4:
                licenseKey.F4 = value;
                break;

            case 5:
                licenseKey.F5 = value;
                break;

            case 6:
                licenseKey.F6 = value;
                break;

            case 7:
                licenseKey.F7 = value;
                break;

            case 8:
                licenseKey.F8 = value;
                break;
            }
        }
Example #9
0
        /// <summary>
        /// Loads the <see cref="LicenseKey"/> object from a file.
        /// </summary>
        /// <remarks>The current object will not be affected. Instead,
        /// you need to assign it manually, eg. licenseKey = licenseKey.LoadFromFile().</remarks>
        /// <returns>Returns the original object if successful. Null otherwise.</returns>
        public static LicenseKey LoadFromFile(this LicenseKey licenseKey)
        {
            string name = "licensekey.skm";

            return(LoadFromFile(licenseKey, name));
        }
Example #10
0
        /// <summary>
        /// Saves the current <see cref="LicenseKey"/> object to file.
        /// </summary>
        /// <returns>Returns the original object if successful. Null otherwise.</returns>
        public static LicenseKey SaveToFile(this LicenseKey licenseKey)
        {
            string name = "licensekey.skm";

            return(SaveToFile(licenseKey, name));
        }
Example #11
0
 /// <summary>
 /// Checks so that the machine code corresponds to the machine code of this computer.
 /// The default hash function is SHA1.
 /// </summary>
 /// <returns></returns>
 public static LicenseKey IsOnRightMachine(this LicenseKey licenseKey)
 {
     return(IsOnRightMachine(licenseKey, SKGL.SKM.getSHA1));
 }
Example #12
0
 /// <summary>
 /// Checks that this object has a valid signature, which means that the content has not been altered
 /// after that it was generated by Serial Key Manager.
 /// </summary>
 /// <param name="rsaPublicKey">The public key (RSA). It can be found here: https://serialkeymanager.com/User/Security </param>
 /// <returns>A key information object if the condition is satisfied. Null otherwise.</returns>
 public static LicenseKey HasValidSignature(this LicenseKey licenseKey, string rsaPublicKey)
 {
     return(HasValidSignature(licenseKey, rsaPublicKey, null));
 }
Example #13
0
 /// <summary>
 /// Checks so that the machine code corresponds to the machine code of this computer.
 /// The default hash function is SHA1.
 /// </summary>
 /// <remarks>Please use <see cref="SKM.V3.Methods.Helpers.IsOnRightMachine(LicenseKey)"/> instead of this method
 /// since it uses SHA256 by default.</remarks>
 /// <param name="allowOverdraft">If floating licensing is enabled with overdraft, this parameter should be set to true.
 /// You can enable overdraft by setting <see cref="ActivateModel.MaxOverdraft"/> to a value greater than 0.
 ///</param>
 /// <returns></returns>
 public static LicenseKey IsOnRightMachine(this LicenseKey licenseKey, bool isFloatingLicense = false, bool allowOverdraft = false)
 {
     return(IsOnRightMachine(licenseKey, SKGL.SKM.getSHA1, isFloatingLicense, allowOverdraft));
 }
Example #14
0
 /// <summary>
 /// Registers an event related to this license key. Note, this methods only works on the .NET Framework.
 /// </summary>
 /// <param name="token">An access token with RegisterEvent permission is required.</param>
 public static void RegisterEvent(this LicenseKey licenseKey, string token, Event eventObj)
 {
     licenseKey.RegisterEvent(token, eventObj, Methods.Helpers.GetMachineCode());
 }
Example #15
0
 /// <summary>
 /// Decrements the <see cref="IntValue"/> by a given amount. (in SKM Platform).
 /// </summary>
 /// <param name="token">The access token. Read more at https://serialkeymanager.com/docs/api/v3/Auth </param>
 /// <param name="decrementValue">The number we should decrement by.</param>
 /// <param name="licenseKey">The license key we should associate with this data object.</param>
 /// <remarks>Note: for more details, please see
 /// <a href="https://serialkeymanager.com/docs/api/v3/IncrementIntValue">https://serialkeymanager.com/docs/api/v3/IncrementIntValue</a> <br/>
 /// </remarks>
 /// <returns>Returns true if successful or false otherwise.</returns>
 public bool DecrementIntValue(string token, int decrementValue, LicenseKey licenseKey)
 {
     return(DecrementIntValue(token, decrementValue, licenseKey, false, 0));
 }
Example #16
0
 /// <summary>
 /// Increments the <see cref="IntValue"/> by a given amount. (in SKM Platform).
 /// </summary>
 /// <param name="token">The access token. Read more at https://serialkeymanager.com/docs/api/v3/Auth </param>
 /// <param name="incrementValue">The number we should increment by.</param>
 /// <param name="licenseKey">The license key we should associate with this data object.</param>
 /// <remarks>Note: for more details, please see
 /// <a href="https://serialkeymanager.com/docs/api/v3/IncrementIntValue">https://serialkeymanager.com/docs/api/v3/IncrementIntValue</a> <br/>
 /// </remarks>
 /// <returns>Returns true if successful or false otherwise.</returns>
 public bool IncrementIntValue(string token, int incrementValue, LicenseKey licenseKey)
 {
     return(IncrementIntValue(token, incrementValue, licenseKey, false, 0));
 }