NetSeal_Helper.NetSeal.LicenseManager.LicenseReader.ReadLicenseFrom C# (CSharp) Method

ReadLicenseFrom() private method

Reads a netseal license file
private ReadLicenseFrom ( string licensePath, string netsealId ) : NetSeal_Helper.NetSeal.LicenseManager.LicenseFile
licensePath string License File Path
netsealId string NetSeal ID
return NetSeal_Helper.NetSeal.LicenseManager.LicenseFile
        internal LicenseFile ReadLicenseFrom(string licensePath, string netsealId)
        {
            if (!File.Exists(licensePath))
                throw new FileNotFoundException("License file not found");

            byte[] derivation = null;
            byte[] decrypted = null;
            var framework = LicenseFramework.Null;

            try {
                derivation = GetDerivationFr2_0(netsealId);
                decrypted = DecryptLicense(File.ReadAllBytes(licensePath), derivation);
                framework = LicenseFramework.Framework2_0;
            }
            catch {
                derivation = GetDerivationFr4_5(netsealId);
                decrypted = DecryptLicense(File.ReadAllBytes(licensePath), derivation);
                framework = LicenseFramework.Framework4_5;
            }

            using (var memoryStream = new MemoryStream(decrypted))
            {
                using (var binaryReader = new BinaryReader(memoryStream))
                {

                    var license = new LicenseFile();
                    license.LicenseName = Path.GetFileName(licensePath);
                    license.ID = netsealId;
                    license.GUID = binaryReader.ReadString();
                    license.Unknown = binaryReader.ReadBoolean();
                    license.Remember = binaryReader.ReadBoolean();
                    license.Framework = framework;
                    if (license.Remember)
                    {
                        license.Username = binaryReader.ReadString();
                        license.Sha1Password = binaryReader.ReadString();
                    }
                    else
                    {
                        license.Username = string.Empty;
                        license.Sha1Password = string.Empty;
                    }
                    derivation = null;
                    decrypted = null;
                    return license;
                }
            }
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Load your Netseal Licenses
        /// </summary>
        private void LoadLocalLicenses()
        {
            LoadLocalLicensesV2();
            return;

            this.ltvLicenses.Items.Clear();

            Logger.LogInformation("Loading local license(s)");

            var licenseReader = new LicenseReader();
            if (!Directory.Exists(licenseReader.LocalPath))
            {
                Logger.LogWarning("No license(s) found");
                return;
            }

            var files = Directory.GetFiles(licenseReader.LocalPath).Where((x) =>
            {
                var fileName = Path.GetFileNameWithoutExtension(x);
                return fileName.Length == 32;
            });

            var counter = 0;

            foreach (var file in files)
            {
                try
                {
                    var fileName = Path.GetFileNameWithoutExtension(file);
                    var dbTuple = IdsDataBase.IDsDataBase[fileName];
                    var id = dbTuple.Item1; //Netseal ID
                    var programName = dbTuple.Item2; //Netseal program name

                    if (!string.IsNullOrEmpty(id))
                    {
                        var licenseFile = licenseReader.ReadLicenseFrom(file, id);
                        //Store the license
                        Licenses.Add(licenseFile);

                        programName = !string.IsNullOrEmpty(programName) ? programName : this.txtUnknownProgramName.Text;

                        ltvLicenses.Items.Add(id).SubItems.AddRange(new string[]
                        {
                            programName,
                            licenseFile.GUID,
                            licenseFile.Remember.ToString(),
                            licenseFile.Username,
                            licenseFile.Sha1Password,
                        });
                        counter++;
                    }
                }
                catch
                {
                    continue;
                }
            }
            Logger.LogInformation("Loaded " + counter + " license(s)");
        }