public List <string> GetAllHashedLicenseKeysByLicenseSet(int licenseSetId) { List <string> hashedKeys = new List <string>(); List <string> keys = GetAllLicenseKeysByLicenseSet(licenseSetId); foreach (string k in keys) { hashedKeys.Add(_hashingProvider.ComputeHash(k, Properties.Resources.KeyHashingAlgo)); } return(hashedKeys); }
public ServiceProduct CreateTestProduct(string licenseKey) { DeleteTestServiceProduct(); ServiceProduct prod = new ServiceProduct(); prod.LicenseId = int.MaxValue; prod.LicenseName = "Test Product License"; prod.LicenseSets = new List <ServiceLicenseSet>(); ServiceLicenseSet ls = new ServiceLicenseSet(); ls.LicenseSetId = int.MaxValue; ls.LicenseId = int.MaxValue; ls.Keys = new List <ServiceLicenseKey>(); ls.LicenseSetName = "Test Product License Set"; ls.LicenseType = LicenseKeyTypeFlag.MultiUser; ls.MaxUsers = 2; ServiceLicenseKey key = new ServiceLicenseKey(); key.CreatedOn = DateTime.Now; key.Key = _hashingProvider.ComputeHash(licenseKey, "SHA256"); key.LicenseSetId = int.MaxValue; key.ActivationCount = 0; ls.Keys.Add(key); prod.LicenseSets.Add(ls); _serviceProductsRepository.SaveServiceProduct(prod); return(_serviceProductsRepository.GetProduct(int.MaxValue)); }
/// <summary> /// Returns the hardware fingerprint for the current system. Requires WMI enabled. /// </summary> /// <param name="type">Type of hardware to use in the Fingerprint</param> /// <returns>Hardware Fingerprint as a String</returns> public string GetHardwareFingerprint(FingerprintTypes type) { string fingerprint = null; try { switch (type) { case FingerprintTypes.Default: fingerprint = _wmiDataProvider.GetPrimaryHardDriveSerial(); break; case FingerprintTypes.HardDriveSerial: fingerprint = _wmiDataProvider.GetPrimaryHardDriveSerial(); break; default: throw new ArgumentOutOfRangeException("type"); } } catch { } if (String.IsNullOrEmpty(fingerprint)) { try { fingerprint = _wmiDataProvider.GetProcessorData(); } catch { } } return(_hashingProvider.ComputeHash(fingerprint, "MD5")); }
public void LogActiviation(string licenseKey, ActivationResults activationResult, string ipAddress) { ActivationLog log = new ActivationLog(); log.LicenseKey = _hashingProvider.ComputeHash(licenseKey, "SHA256"); log.ActivationResult = activationResult; log.IpAddress = ipAddress; log.Timestamp = DateTime.Now; _activationLogRepository.SaveActivationLog(log); }
public bool ValidatePassword(byte[] pwd, byte[] pwdCheck, byte[] salt) { var formattedPwdCheck = _saltStrategy.Format(pwdCheck, salt); var hashedPwd = _hashProvider.ComputeHash(formattedPwdCheck); if (pwd.Length != hashedPwd.Length) { return(false); } for (var i = 0; i < pwd.Length; i++) { if (pwd[i] != hashedPwd[i]) { return(false); } } return(true); }
public bool VaildatePassword(string pwd, byte[] pwdCheck, byte[] salt) { var formattedPwdCheck = _saltStrategy.Format(pwdCheck, salt); var hashedPwd = _hashingProvider.ComputeHash(formattedPwdCheck); var userPwdData = Encoding.UTF8.GetString(hashedPwd); if (pwd.Length != userPwdData.Length) { return(false); } for (var i = 0; i < pwd.Length; i++) { if (pwd[i] != userPwdData[i]) { return(false); } } return(true); }
// 傳入資料庫的密碼 , 使用者輸入的 , 加料 public bool ValidatePassword(byte[] pwd, byte[] pwdCheck, byte[] salt) { //將使用者輸入的加料 var formattedPwd = _saltStrategy.Format(pwdCheck, salt); //先加過料再作Hash var hashedPwd = _hashingProvider.ComputeHash(formattedPwd); //如果兩個長度不一樣(資料庫的和user輸入的) if (pwd.Length != hashedPwd.Length) { return(false); } //比對每個字元是否正確 for (var i = 0; i < pwd.Length; i++) { if (pwd[i] != hashedPwd[i]) { return(false); } } return(true); }
/// <summary> /// Authorizes a license key to check to see if it can be activated. If not, logs the failure reason and /// returns false. /// </summary> /// <param name="licenseKey"></param> /// <param name="licenseBase"></param> /// <param name="hardwareFingerprint"></param> /// <returns></returns> public bool AuthorizeLicenseForActivation(string licenseKey, ServiceLicense licenseBase, string hardwareFingerprint) { KeyData keyData = _licenseKeyService.GetLicenseKeyData(licenseKey, licenseBase, true); // Step 1: Validate the physical key bool keyValid = _licenseKeyService.ValidateLicenseKey(licenseKey, licenseBase, true); if (!keyValid) { _activationLogService.LogActiviation(licenseKey, ActivationResults.ValidationFailure, null); return(false); } SecureString hashedLicenseKey = SecureStringHelper.StringToSecureString(_hashingProvider.ComputeHash(licenseKey, Resources.KeyHashAlgo)); hashedLicenseKey.MakeReadOnly(); // Step 2: Validate the key against the service if (!DoesKeyExistForLicenseSet(SecureStringHelper.SecureStringToString(hashedLicenseKey), keyData.LicenseSetId)) { _activationLogService.LogActiviation(licenseKey, ActivationResults.UnknownKeyFailure, null); return(false); } // Step 3: Is this key used already if (!IsKeyAvialable(SecureStringHelper.SecureStringToString(hashedLicenseKey), keyData.LicenseSetId, hardwareFingerprint)) { _activationLogService.LogActiviation(licenseKey, ActivationResults.TooManyFailure, null); return(false); } return(true); }
private string GetBucketName() { string hashData = DateTime.Now.Month + Environment.MachineName + DateTime.Now.Year + DateTime.Now.Day; return(_hashingProvider.ComputeHash(hashData, "MD5")); }