/// <summary> /// Generazione del token di autenticazione per l'utente specificato /// </summary> /// <param name="userId">User id dell'utente proprietario del token</param> /// <param name="tokenType">Tipo di token da generare</param> /// <param name="milliseconds">Durata del token espressa in millisecondi</param> /// <param name="keyLength">Lunghezza della chiave espressa in numero di caratteri</param> /// <param name="initializationVectorLength">Lunghezza dell'initialization vector espressa in numero di caratteri</param> /// <returns>Token criptato</returns> public override string Generate(string userId, AuthTokenManager.TokenTypeEnum tokenType, double milliseconds, AuthTokenManager.KeyLengthEnum keyLength, AuthTokenManager.KeyLengthEnum initializationVectorLength) { // Chiave privata, vettore di inizializzazione e la userid pulita String key, initializationVector, cleanedUserId; // Pulizia dello user id cleanedUserId = userId.Trim().ToUpper(); // Decifratura lunghezza della chiave e dell'initialization vector int kLength = this.DecodeKeyLength(keyLength); int ivLength = this.DecodeKeyLength(initializationVectorLength); // Generazione della chiavi key = KeyGeneratorHelper.BetterRandomString(kLength); initializationVector = KeyGeneratorHelper.BetterRandomString(ivLength); try { CryptoString crypto = new CryptoString(key, initializationVector); string encodedValue = crypto.Encrypt(String.Format(ENCRYPTED_VALUE_FORMAT, cleanedUserId, GetSessionId(), this.GetActualDateFromDB(), tokenType, this.GetExpirationDate(tokenType, milliseconds))); // Salvataggio token su db this.SaveToken(key, encodedValue, initializationVector, cleanedUserId); return(string.Format("{0}{1}", TOKEN_PREFIX, encodedValue)); } catch (Exception ex) { throw new EncryptionException(ex); } }
public virtual float GetBestScoreForLevel(int lvlNr, bool checkUserID) { if (MFPClassic.Hook.devMode) { return(0); } float num1 = 0.0f; for (float num2 = new float(); (double)num2 <= 2.0; ++num2) { int num3 = SavedData.GetInt(CryptoString.Encrypt(RuntimeServices.op_Addition(RuntimeServices.op_Addition(RuntimeServices.op_Addition("lvlScore", (object)lvlNr), "diff"), (object)num2))); if ((double)num3 > (double)num1) { if (checkUserID) { string str = SavedData.GetString(CryptoString.Encrypt(RuntimeServices.op_Addition(RuntimeServices.op_Addition(RuntimeServices.op_Addition(RuntimeServices.op_Addition("lvlScore", (object)lvlNr), "diff"), (object)num2), "ID"))); if (this.userID == "0" && str != "-1" && str != "-999" || str == this.userID) { num1 = (float)num3; } } else { num1 = (float)num3; } } } return(num1); }
public virtual float GetBestTimeForLevel(int lvlNr) { float num1 = 9999999f; for (float num2 = new float(); (double)num2 <= 2.0; ++num2) { float num3 = SavedData.GetFloat(CryptoString.Encrypt(RuntimeServices.op_Addition(RuntimeServices.op_Addition(RuntimeServices.op_Addition("lvlTime", (object)lvlNr), "diff"), (object)num2))); if ((double)num3 != 0.0 && (double)num3 < (double)num1) { num1 = num3; } } return(num1); }
public void TestCryptoString() { string key = CryptoString.MakeKey(); string iv = CryptoString.MakeIV(); string test = "Test String"; CryptoString cs = new CryptoString(key, iv); string crypto = cs.Encrypt(test); string plain = cs.Decrypt(crypto); Assert.AreEqual(test, plain); }
public virtual void CheckForBrokenScores() { for (int index = new int(); index <= 52; ++index) { for (float num1 = new float(); (double)num1 <= 2.0; ++num1) { int num2 = SavedData.GetInt(CryptoString.Encrypt(RuntimeServices.op_Addition(RuntimeServices.op_Addition(RuntimeServices.op_Addition("lvlScore", (object)index), "diff"), (object)num1))); if (num2 >= 9999999 || num2 < 0) { MonoBehaviour.print((object)RuntimeServices.op_Addition("BROKEN SCORE DETECTED: ", (object)num2)); SavedData.SetInt(CryptoString.Encrypt(RuntimeServices.op_Addition(RuntimeServices.op_Addition(RuntimeServices.op_Addition("lvlScore", (object)index), "diff"), (object)num1)), 0); } } } }
public void TestCryptoStringDefaultConstructor() { string key = CryptoString.MakeKey(); string iv = CryptoString.MakeIV(); string test = "Test String"; CryptoString cs = new CryptoString { Key = key, IV = iv }; string crypto = cs.Encrypt(test); string plain = cs.Decrypt(crypto); Assert.AreEqual(test, plain); }
public void TestCryptoStringNoKeyEncrypt() { string test = "Test String"; CryptoString cs = new CryptoString(); try { string crypto = cs.Encrypt(test); string plain = cs.Decrypt(crypto); Assert.Fail("Should have thrown an exception"); } catch (Exception ex) { Assert.AreEqual("savedKey and savedIV must be non-null.", ex.Message); } }
public virtual void Update() { if (this.simulateMousePos) { this.fakeMousePos += new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")) * (0.005f + this.simulateMousePosSensitivity) * 68f * (Mathf.Round((float)(Screen.width + Screen.height)) / 2f / 1500f); this.fakeMousePos.x = Mathf.Clamp(this.fakeMousePos.x, 0.0f, (float)Screen.width); this.fakeMousePos.y = Mathf.Clamp(this.fakeMousePos.y, 0.0f, (float)Screen.height); } if (!this.allowLeaderboard || !this.uploadAllScores) { return; } if (this.curUploadAllScores <= 52) { if (!this.OkToUploadScore()) { return; } string empty = string.Empty; for (float num1 = new float(); (double)num1 <= 2.0; ++num1) { if (SavedData.GetString(CryptoString.Encrypt(RuntimeServices.op_Addition(RuntimeServices.op_Addition(RuntimeServices.op_Addition(RuntimeServices.op_Addition("lvlScore", (object)this.curUploadAllScores), "diff"), (object)num1), "ID"))) == "-999") { int num2 = empty == "-999" ? 1 : 0; } } string leaderboardName = this.GetLeaderboardName(this.curUploadAllScores, string.Empty, false); if (leaderboardName != string.Empty) { float num1 = new float(); float num2 = !this.speedrunnerLeaderboard ? this.GetBestScoreForLevel(this.curUploadAllScores, true) : this.GetBestTimeForLevel(this.curUploadAllScores) * 1000f; if ((double)num2 > 0.0 && (double)num2 < 9999999.0) { this.steamLeaderboardsScript.DoUploadScore((int)num2, leaderboardName); MFPClassic.MFPEditorUtils.Log("Uploading leaderboard score for:" + leaderboardName); } } ++this.curUploadAllScores; } else { this.uploadAllScores = false; } }
public IList GetPersonOnJob(string sUserCode, string sPassWord, string sOperationJobId) { PersonOnJob o; ObjectQuery oQuery = new ObjectQuery(); string sTempPassWord = string.Empty; if (string.IsNullOrEmpty(sPassWord)) { sPassWord = ""; } sTempPassWord = CryptoString.Encrypt(sPassWord, sPassWord); //oQuery.AddCriterion(Expression.Eq("StandardPerson.Password", sPassWord)); oQuery.AddCriterion(Expression.Eq("StandardPerson.Code", sUserCode)); oQuery.AddCriterion(Expression.Eq("OperationJob.Id", sOperationJobId)); oQuery.AddCriterion(Expression.Eq("State", 1)); oQuery.AddFetchMode("OperationJob", FetchMode.Eager); oQuery.AddFetchMode("StandardPerson", FetchMode.Eager); oQuery.AddFetchMode("OperationJob.OperationOrg", FetchMode.Eager); IList lstResult = dao.ObjectQuery(typeof(PersonOnJob), oQuery); for (int i = lstResult.Count - 1; i > -1; i--) { PersonOnJob oPersonOnJob = lstResult[i] as PersonOnJob; if (oPersonOnJob.StandardPerson != null) { if (string.Equals(oPersonOnJob.StandardPerson.Password, sTempPassWord) || string.Equals(oPersonOnJob.StandardPerson.Password, sPassWord)) { continue; } else if (string.IsNullOrEmpty(oPersonOnJob.StandardPerson.Password) && string.IsNullOrEmpty(sTempPassWord)) { continue; } else { lstResult.RemoveAt(i); } } } return(lstResult); }
public virtual void DoVersionCheck() { MonoBehaviour.print((object)"Checking build number..."); float num1 = SavedData.GetFloat(CryptoString.Encrypt("BuildVersionNumber")); if ((double)this.currentBuildVersionNumber == 0.0 || (double)num1 == (double)this.currentBuildVersionNumber || ((double)num1 == 1.01999998092651 || (double)this.currentBuildVersionNumber != 1.02999997138977)) { return; } for (int index = new int(); index <= 52; ++index) { for (float num2 = new float(); (double)num2 <= 2.0; ++num2) { if (SavedData.HasKey(CryptoString.Encrypt(RuntimeServices.op_Addition(RuntimeServices.op_Addition(RuntimeServices.op_Addition(RuntimeServices.op_Addition("lvlScore", (object)index), "diff"), (object)num2), "ID")))) { SavedData.SetString(CryptoString.Encrypt(RuntimeServices.op_Addition(RuntimeServices.op_Addition(RuntimeServices.op_Addition(RuntimeServices.op_Addition("lvlScore", (object)index), "diff"), (object)num2), "ID")), "-1"); } } } SavedData.SetFloat(CryptoString.Encrypt("BuildVersionNumber"), this.currentBuildVersionNumber); MonoBehaviour.print((object)"Save from older build. Disabling auto-score-upload for saved scores on boot."); }
/// <summary> /// 获取身份验证的Value /// </summary> /// <returns></returns> public static string GetAuthMenuIdEncryptValue(string key) { return(CryptoString.Encrypt(key, key)); }