public void Import1ByteNotPasswordProtected() { byte[] shortKey = new byte[1]; CryptographyUtility.GetRandomBytes(shortKey); ImportExportAssert(shortKey, string.Empty); }
public void Import1024BytePasswordProtected() { byte[] shortKey = new byte[1024]; CryptographyUtility.GetRandomBytes(shortKey); ImportExportAssert(shortKey, "54321"); }
private void ImportExportAssert(byte[] plainTextKey, string passphrase) { this.utility.Export(plainTextKey, Destination, passphrase); byte[] importKey = this.utility.Import(Destination, passphrase); Assert.IsTrue(CryptographyUtility.CompareBytes(plainTextKey, importKey), "key contents"); }
public override void SceneStackPoped(Dictionary <string, object> param) { switch (lastPlayState) { case LastPlayState.Play: if (param.ContainsKey("PerfectTrialSucceess") && (bool)param["PerfectTrialSucceess"]) { var gameUtility = (PPDGameUtility)param["GameUtility"]; PerfectTrialCache.Instance.AddPerfectTrial(CryptographyUtility.Getx2Encoding( gameUtility.SongInformation.GetScoreHash(gameUtility.Difficulty))); ssm.SelectedSongInformation.UpdatePerfectTrialInfo(); } allowcommand = true; cc.Next(); mss.DisapperFinish += cc.Show; fm.RemoveFocus(); cc.Vanish(); menuMovie.Seek(ssm.SelectedSongInformation.SongInfo.ThumbStartTime); menuMovie.FadeIn(); sic.UpdateResult(); sic.UpdatePerfectTrials(); goto default; default: menuMovie.Play(); break; } menuMovie.CheckLoopAvailable = true; goToPlay = false; black.Alpha = 0; }
public void Import2BytePasswordProtected() { byte[] shortKey = new byte[2]; CryptographyUtility.GetRandomBytes(shortKey); ImportExportAssert(shortKey, "12345"); }
public void VerifyHashAsUnique() { byte[] hash1 = SaltedHashProvider.CreateHash(this.plainText); byte[] hash2 = SaltedHashProvider.CreateHash(this.plainText); Assert.IsFalse(CryptographyUtility.CompareBytes(hash1, hash2)); }
public DataSourceResult GetOrders(DataSourceRequest request) { Hashtable fltr = new Hashtable(); Common.CommonFunction.PopulateFiltersInHashTable(request.Filters, fltr); ObjectParameter objparam = new ObjectParameter("TotalRecords", System.Data.DbType.Int16); var distribut = fltr.ContainsKey("Distributor") ? Convert.ToInt32(fltr["Distributor"].ToString()) : 0; DateTime?orderDate = (fltr.ContainsKey("Date") && fltr["Date"] != null) ? Convert.ToDateTime(fltr["Date"]) : (DateTime?)null; var queryResult = db.Order_Get(orderDate, distribut, request.Page, request.PageSize, objparam).ToList() .Select(i => new OrderViewModel() { OrderId = i.OrderId, Date = i.ModifiedDate.Date.ToString("dd MMM yyy"), Distributor = i.Distributor, IsDispatched = i.IsDispatched, TotalItems = (int)i.TotalItems, TotalItemsPending = (int)i.TotalItemsPending, ProcessOrder = CryptographyUtility.GetEncryptedQueryString(new { orderId = i.OrderId }), ViewOrder = CryptographyUtility.GetEncryptedQueryString(new { orderId = i.OrderId }) }); DataSourceResult dsr = new DataSourceResult(); dsr.Data = queryResult; dsr.Total = (int)objparam.Value; return(dsr); }
public void GetHexStringFromBytes() { byte[] bytes = new byte[] { 0, 255 }; string hex = CryptographyUtility.GetHexStringFromBytes(bytes); Assert.AreEqual("00FF", hex); }
private bool CheckSameScore() { var hashs = new Dictionary <string, PPDEditor.AvailableDifficulty>(); var sha256 = new SHA256Managed(); bool found = false; foreach (AvailableDifficulty difficulty in EditorForm.DifficultyArray) { if (difficulty == AvailableDifficulty.None) { continue; } if ((PublishDifficulty & difficulty) == difficulty) { var filePath = Path.Combine(WindowUtility.MainForm.CurrentProjectDir, difficulty + ".ppd"); var hash = CryptographyUtility.Getx2Encoding(sha256.ComputeHash(File.ReadAllBytes(filePath))); if (hashs.ContainsKey(hash)) { MessageBox.Show(String.Format(Utility.Language["ScoreHashCollision"], hashs[hash], difficulty)); found = true; } else { hashs.Add(hash, difficulty); } } } return(!found); }
private void SetKeyBox(byte[] key) { if (key.Length > 0) { keyBox.Text = CryptographyUtility.GetHexStringFromBytes(key); } }
public void GetRandomBytes() { int expected = 24; byte[] random = CryptographyUtility.GetRandomBytes(expected); Assert.AreEqual(expected, random.Length); }
void updateTimerCallBack(int obj) { var updateExecutor = new UpdateRoomInfoExecutor(ContextManager.WebManager, userList.Count, currentSong != null ? CryptographyUtility.Getx2Encoding(currentSong.Hash) : ""); updateExecutor.Finished += UpdateExecutor_Finished; updateExecutor.Start(); }
public void CompareBytesPass() { byte[] first = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; byte[] second = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; Assert.AreEqual(first, second); Assert.IsTrue(CryptographyUtility.CompareBytes(first, second)); }
public void ZeroOutBytes() { byte[] bytes = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; CryptographyUtility.ZeroOutBytes(bytes); Assert.AreEqual(expected, bytes); }
public void CreateHMACSHA1Key() { KeyedHashAlgorithmKeyCreator keyCreator = new KeyedHashAlgorithmKeyCreator(typeof(HMACSHA1).AssemblyQualifiedName); Assert.AreEqual(64, keyCreator.KeyLength); Assert.AreEqual(64, keyCreator.GenerateKey().Length); Assert.IsFalse(CryptographyUtility.CompareBytes(keyCreator.GenerateKey(), keyCreator.GenerateKey())); }
public void CompareBytesFailWithNull() { byte[] bytes = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; Assert.IsFalse(CryptographyUtility.CompareBytes(bytes, null)); Assert.IsFalse(CryptographyUtility.CompareBytes(null, bytes)); Assert.IsFalse(CryptographyUtility.CompareBytes(null, null)); }
public string GenerateFulfillmentUri(byte[] publicKey, byte[] signature) { var asn1 = new Asn1lib(publicKey); var serializedUriData = asn1.SerializeBinary(signature); var fulfillmentUri = CryptographyUtility.SerializeUri(serializedUriData); return(fulfillmentUri); }
public void CompareBytesFail() { byte[] first = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; byte[] second = { 1, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; Assert.AreNotEqual(first, second); Assert.IsFalse(CryptographyUtility.CompareBytes(first, second)); }
public void UniqueSaltedHashes() { IHashProvider hashProviderWithSalt = SaltedHashProvider; byte[] providerHash1 = hashProviderWithSalt.CreateHash(plainText); byte[] providerHash2 = hashProviderWithSalt.CreateHash(plainText); Assert.IsFalse(CryptographyUtility.CompareBytes(providerHash1, providerHash2), "compare"); }
public string GetEncryptedStringCookie(string name, string defaultValue) { if (RequestCookies[name] != null) { return(CryptographyUtility.DecryptString(RequestCookies[name].Value)); } return(defaultValue); }
public void Properties() { byte[] key = new byte[] { 0, 1, 2, 3, 4, 5, 6 }; KeyedHashAlgorithmProviderData data = new KeyedHashAlgorithmProviderData(); data.Key = key; Assert.IsTrue(CryptographyUtility.CompareBytes(key, data.Key)); }
public void CombineBytes() { byte[] test1 = new byte[] { 0, 1, 2, 3 }; byte[] test2 = new byte[] { 0, 1, 2, 3 }; byte[] combinedBytes = CryptographyUtility.CombineBytes(test1, test2); Assert.AreEqual(test1.Length + test2.Length, combinedBytes.Length); }
public int GetEncryptedIntCookie(string name) { if (RequestCookies[name] != null) { return(int.Parse(CryptographyUtility.DecryptString(RequestCookies[name].Value))); } return(-1); }
public void EncryptAndDecryptBytes() { byte[] encrypted = Cryptographer.EncryptSymmetric(symmInstance, plainTextBytes); Assert.IsFalse(CryptographyUtility.CompareBytes(plainTextBytes, encrypted)); byte[] decrypted = Cryptographer.DecryptSymmetric(symmInstance, encrypted); Assert.IsTrue(CryptographyUtility.CompareBytes(plainTextBytes, decrypted)); }
internal UserValidateDetail UserValidate(string userName, string password) { Dictionary <string, SqlParameter> cmdParameters = new Dictionary <string, SqlParameter>(); cmdParameters["UserName"] = new SqlParameter("UserName", userName); cmdParameters["Password"] = new SqlParameter("Password", CryptographyUtility.EncryptPassword(password, userName)); SqlParameter outPutParameter1 = new SqlParameter(); outPutParameter1.ParameterName = "@Name"; outPutParameter1.SqlDbType = System.Data.SqlDbType.VarChar; outPutParameter1.Size = 255; outPutParameter1.Direction = System.Data.ParameterDirection.Output; cmdParameters["@Name"] = outPutParameter1; SqlParameter outPutParameter2 = new SqlParameter(); outPutParameter2.ParameterName = "@GroupID"; outPutParameter2.SqlDbType = System.Data.SqlDbType.Int; outPutParameter2.Size = 255; outPutParameter2.Direction = System.Data.ParameterDirection.Output; cmdParameters["@GroupID"] = outPutParameter2; SqlParameter outPutParameter3 = new SqlParameter(); outPutParameter3.ParameterName = "@ERRNo"; outPutParameter3.SqlDbType = System.Data.SqlDbType.Int; outPutParameter3.Size = 255; outPutParameter3.Direction = System.Data.ParameterDirection.Output; cmdParameters["@ERRNo"] = outPutParameter3; SqlParameter outPutParameter4 = new SqlParameter(); outPutParameter4.ParameterName = "@ERRORDESC"; outPutParameter4.SqlDbType = System.Data.SqlDbType.VarChar; outPutParameter4.Size = 255; outPutParameter4.Direction = System.Data.ParameterDirection.Output; cmdParameters["@ERRORDESC"] = outPutParameter4; SqlParameter outPutParameter5 = new SqlParameter(); outPutParameter5.ParameterName = "@UserID"; outPutParameter5.SqlDbType = System.Data.SqlDbType.Int; outPutParameter5.Size = 255; outPutParameter5.Direction = System.Data.ParameterDirection.Output; cmdParameters["@UserID"] = outPutParameter5; UserValidateDetail userValidateDetail = new UserValidateDetail(); dbutility.ExecuteNonQuery("QuotationDb", "dbo.UserValidate", cmdParameters); userValidateDetail.Name = outPutParameter1.Value == null ? null : outPutParameter1.Value.ToString(); userValidateDetail.GroupId = outPutParameter2.Value == null ? -1 : (outPutParameter2.Value.ToString() == string.Empty ? -1 : int.Parse(outPutParameter2.Value.ToString())); userValidateDetail.Code = outPutParameter3.Value == null ? -1 : (outPutParameter3.Value.ToString() == string.Empty ? -1 : int.Parse(outPutParameter3.Value.ToString())); userValidateDetail.Info = outPutParameter4.Value == null ? "ERROR" : outPutParameter4.Value.ToString(); userValidateDetail.UserId = outPutParameter5.Value == null ? -1 : (outPutParameter5.Value.ToString() == string.Empty ? -1 : int.Parse(outPutParameter5.Value.ToString())); return(userValidateDetail); }
public void GenerateRandomBytes() { int rndSize = 16; byte[] rnd1 = CryptographyUtility.GetRandomBytes(rndSize); byte[] rnd2 = CryptographyUtility.GetRandomBytes(rndSize); Assert.IsFalse(CryptographyUtility.CompareBytes(rnd1, rnd2)); }
public void SetEncryptedCookie(string name, object value) { if (value != null) { HttpCookie cookie = new HttpCookie(name, CryptographyUtility.EncryptString(value)); cookie.Path = "/"; ResponseCookies.Add(cookie); } }
/// <summary> /// Hashes SecureString and returns it as string. /// </summary> /// <param name="secureString">The SecureString to hash.</param> /// <returns>Hashed SecureString's value.</returns> public static string HashValue(this SecureString secureString) { var bytes = secureString.ConvertToBytes(); var hashedString = CryptographyUtility.HashBytes(bytes); Array.Clear(bytes, 0, bytes.Length); return(hashedString); }
private void ReadCbc(Stream inputStream) { BigEndianBinaryReader reader = new BigEndianBinaryReader(inputStream, Encoding.ASCII, true); reader.Read(_iv, 0, EncryptionIvCbcSize); byte[] encryptedData = new byte[inputStream.Length - EncryptionIvCbcSize]; reader.Read(encryptedData, 0, encryptedData.Length); Data = CryptographyUtility.DecryptAesCbc(new MemoryStream(encryptedData), _key, _iv); }
public void TestConstruction() { byte[] bytes = new byte[] { 1, 2, 3, 4 }; using (KeyAlgorithmPair pair = new KeyAlgorithmPair(bytes, "foo")) { Assert.AreEqual("foo", pair.AlgorithmTypeName); Assert.IsTrue(CryptographyUtility.CompareBytes(bytes, pair.Key)); } }