예제 #1
0
        private bool IsValid(SecureLicense license)
        {
            byte[] hashBytes = Convert.FromBase64String(license.Key);
            byte[] salt      = new byte[license.RandomSaltLength];

            Array.Copy(hashBytes, 0, salt, 0, license.RandomSaltLength);

            byte[] hash = new Rfc2898DeriveBytes(license.Password, salt, license.Iterations).GetBytes(hashBytes.Length - salt.Length);

            for (int i = 0; i < hash.Length; i++)
            {
                if (hashBytes[i + salt.Length] != hash[i])
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #2
0
        public void GenerateLicense(string filePath)
        {
            var    license   = new SecureLicense(Key, Password, Iterations, RandomSaltLength);
            string directory = Path.GetDirectoryName(filePath);

            // If file name not specified, give a default file name
            string fileName = (!string.IsNullOrEmpty(Path.GetFileName(filePath)) ? Path.GetFileName(filePath) : "license.lic");

            // Create the directory if it does not exist
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            // Combine the directories, for a full write path
            directory = Path.Combine(directory, fileName);

            // Write our license file
            WriteToBinaryFile(directory, license);
        }