public Key(string licenseTemplate, Checksum.ChecksumType checksumAlgorithm) { ChecksumAlgorithm = checksumAlgorithm; LicenseTemplate = licenseTemplate; // create the random object _rnd = new Random(unchecked((int)DateTime.Now.Ticks)); // initialzie the license key _strLicensekey = string.Empty; _tokens = new List<Token>(); }
/// <summary> /// Get the checksum number so we can add it into the license key string. /// </summary> /// <param name="licensekey">The license key string.</param> /// <param name="numberLength">The size of the field.</param> /// <param name="includeLicensekey">Include the original license key as part of the return value.</param> private string GetChecksumNumber(string licensekey, int numberLength, bool includeLicensekey) { // // create the checksum class // var chk = new Checksum(); var remain = numberLength%4; if (remain != 0) { throw new ApplicationException("For Bits values each block should be a multiple of 4"); } numberLength = numberLength/4; chk.ChecksumAlgorithm = ChecksumAlgorithm; chk.CalculateChecksum(licensekey); if (includeLicensekey) { var csum = chk.ChecksumNumber; licensekey = licensekey + NumberDisplay.CreateNumberString(csum, numberLength); } else { var csum = chk.ChecksumNumber; licensekey = NumberDisplay.CreateNumberString(csum, numberLength); } return licensekey; }