public string PackToken(Token token) { StringBuilder sb = new StringBuilder(); sb.Append(_numberDataGeneratorProvider.GenerateRandomNumber(0, 9)); sb.Append(_numberDataGeneratorProvider.GenerateRandomNumber(0, 9)); sb.Append(token.Timestamp.Day.ToString().PadLeft(2, char.Parse("0"))); sb.Append(_numberDataGeneratorProvider.GenerateRandomNumber(0, 9)); sb.Append(_numberDataGeneratorProvider.GenerateRandomNumber(0, 9)); sb.Append(token.Timestamp.Month.ToString().PadLeft(2, char.Parse("0"))); string year = token.Timestamp.Year.ToString(); sb.Append(year.Substring(0, 2)); sb.Append(token.Timestamp.Hour.ToString().PadLeft(2, char.Parse("0"))); sb.Append(token.Data); sb.Append(token.Timestamp.Minute.ToString().PadLeft(2, char.Parse("0"))); sb.Append(_numberDataGeneratorProvider.GenerateRandomNumber(0, 9)); sb.Append(year.Substring(2, 2)); sb.Append(_numberDataGeneratorProvider.GenerateRandomNumber(0, 9)); sb.Append(_numberDataGeneratorProvider.GenerateRandomNumber(0, 9)); sb.Append(_numberDataGeneratorProvider.GenerateRandomNumber(0, 9)); return sb.ToString(); }
public ClientLicense ActivateLicenseKey(string licenseKey, Guid? token, bool isOffline, ClientLicense scutexLicense) { /* This method used to live in the LicenseKeyService class, where it should be * but because of a circular reference in the WebServicesProvider and the ServicesLibrary * project requiring the LicenseKeyService to valid keys it was causing and error and had * to be moved here. */ if (_licenseKeyService.ValidateLicenseKey(licenseKey, scutexLicense, true)) { Token t = new Token(); t.Data = scutexLicense.ServiceToken; t.Timestamp = DateTime.Now; string packedToken = _packingService.PackToken(t); LicenseActivationPayload payload = new LicenseActivationPayload(); payload.LicenseKey = licenseKey; payload.ServiceLicense = new ServiceLicense(scutexLicense); payload.Token = token; if (!isOffline) { ActivationResult result = _licenseActiviationProvider.ActivateLicense(scutexLicense.ServiceAddress, packedToken, GetClientStandardEncryptionInfo(scutexLicense), payload, scutexLicense); if (result != null && result.WasRequestValid && result.ActivationSuccessful) { scutexLicense.IsLicensed = true; scutexLicense.IsActivated = true; scutexLicense.ActivatingServiceId = result.ServiceId; scutexLicense.ActivationToken = result.ActivationToken; scutexLicense.ActivatedOn = DateTime.Now; scutexLicense.ActivationLastCheckedOn = DateTime.Now; _clientLicenseService.SaveClientLicense(scutexLicense); return scutexLicense; } } else { scutexLicense.IsLicensed = true; scutexLicense.IsActivated = false; scutexLicense.ActivatingServiceId = null; scutexLicense.ActivationToken = null; scutexLicense.ActivatedOn = DateTime.Now; scutexLicense.ActivationLastCheckedOn = DateTime.Now; _clientLicenseService.SaveClientLicense(scutexLicense); return scutexLicense; } } return scutexLicense; }
public void CanPackAndUnpackToken() { NumberDataGenerator numberDataGenerator = new NumberDataGenerator(); PackingService packingService = new PackingService(numberDataGenerator); Token t = new Token(); t.Data = tokenData; t.Timestamp = DateTime.Now; string packedToken = packingService.PackToken(t); Token unpackedToken = packingService.UnpackToken(packedToken); Assert.AreEqual(tokenData, unpackedToken.Data); Assert.AreEqual(t.Timestamp.Day, unpackedToken.Timestamp.Day); Assert.AreEqual(t.Timestamp.Month, unpackedToken.Timestamp.Month); Assert.AreEqual(t.Timestamp.Year, unpackedToken.Timestamp.Year); Assert.AreEqual(t.Timestamp.Hour, unpackedToken.Timestamp.Hour); Assert.AreEqual(t.Timestamp.Minute, unpackedToken.Timestamp.Minute); }
public Token UnpackToken(string data) { Token t = new Token(); string decryptedToken = data; // Remove the Preamble and Tail decryptedToken = decryptedToken.Remove(0, 2); decryptedToken = decryptedToken.Remove(decryptedToken.Length - 3, 3); string day = decryptedToken.Substring(0, 2); decryptedToken = decryptedToken.Remove(0, 2); // Remove pad decryptedToken = decryptedToken.Remove(0, 2); string month = decryptedToken.Substring(0, 2); decryptedToken = decryptedToken.Remove(0, 2); string year = decryptedToken.Substring(0, 2); year = year + decryptedToken.Substring(decryptedToken.Length - 2, 2); decryptedToken = decryptedToken.Remove(0, 2); decryptedToken = decryptedToken.Remove(decryptedToken.Length - 2, 2); // Remove pad decryptedToken = decryptedToken.Remove(decryptedToken.Length - 1, 1); string hour = decryptedToken.Substring(0, 2); decryptedToken = decryptedToken.Remove(0, 2); string minute = decryptedToken.Substring(decryptedToken.Length - 2, 2); decryptedToken = decryptedToken.Remove(decryptedToken.Length - 2, 2); t.Timestamp = new DateTime(int.Parse(year), int.Parse(month), int.Parse(day), int.Parse(hour), int.Parse(minute), 0); t.Data = decryptedToken; return t; }
public static void HashTokenWithSalt() { HashingProvider provider = new HashingProvider(); Console.WriteLine(provider.ComputeHashWithSalt("b$7SDt%43J*a!9", "SHA256", null)); PackingService service = new PackingService(new NumberDataGenerator()); Token t = new Token(); t.Data = "MXLBEcLe6/i1CjdyomC7T0vTlACTXpdRmnxcDXDE8yDuCal0xA=="; t.Timestamp = DateTime.Now; Console.WriteLine(service.PackToken(t)); SymmetricEncryptionProvider encryption = new SymmetricEncryptionProvider(); EncryptionInfo ei = new EncryptionInfo(); ei.HashAlgorithm = "SHA1"; ei.InitVector = "a01JQ3481Ahnqwe9"; ei.Iterations = 2; ei.KeySize = 256; ei.PassPhrase = "Da*eW6_EzU4_swuk8*hU"; ei.SaltValue = "VuW9uDrE"; Console.WriteLine(encryption.Encrypt("861641072009MXLBEcLe6/i1CjdyomC7T0vTlACTXpdRmnxcDXDE8yDuCal0xA==41410860", ei)); Console.WriteLine(); Console.WriteLine("Press enter to exit."); Console.ReadLine(); }
public Token GetClientToken() { Token t = new Token(); t.Data = _clientRequestToken; t.Timestamp = DateTime.Now; return t; }
public Token GetManagementToken() { Token t = new Token(); t.Data = _managementRequestToken; t.Timestamp = DateTime.Now; return t; }