Esempio n. 1
0
        public void Import1ByteNotPasswordProtected()
        {
            byte[] shortKey = new byte[1];
            CryptographyUtility.GetRandomBytes(shortKey);

            ImportExportAssert(shortKey, string.Empty);
        }
Esempio n. 2
0
        public void Import1024BytePasswordProtected()
        {
            byte[] shortKey = new byte[1024];
            CryptographyUtility.GetRandomBytes(shortKey);

            ImportExportAssert(shortKey, "54321");
        }
Esempio n. 3
0
        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");
        }
Esempio n. 4
0
        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;
        }
Esempio n. 5
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));
        }
Esempio n. 7
0
        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);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
 private void SetKeyBox(byte[] key)
 {
     if (key.Length > 0)
     {
         keyBox.Text = CryptographyUtility.GetHexStringFromBytes(key);
     }
 }
Esempio n. 11
0
        public void GetRandomBytes()
        {
            int expected = 24;

            byte[] random = CryptographyUtility.GetRandomBytes(expected);
            Assert.AreEqual(expected, random.Length);
        }
Esempio n. 12
0
        void updateTimerCallBack(int obj)
        {
            var updateExecutor = new UpdateRoomInfoExecutor(ContextManager.WebManager, userList.Count,
                                                            currentSong != null ? CryptographyUtility.Getx2Encoding(currentSong.Hash) : "");

            updateExecutor.Finished += UpdateExecutor_Finished;
            updateExecutor.Start();
        }
Esempio n. 13
0
        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));
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        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()));
        }
Esempio n. 16
0
        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);
        }
Esempio n. 18
0
        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));
        }
Esempio n. 19
0
        public void UniqueSaltedHashes()
        {
            IHashProvider hashProviderWithSalt = SaltedHashProvider;

            byte[] providerHash1 = hashProviderWithSalt.CreateHash(plainText);
            byte[] providerHash2 = hashProviderWithSalt.CreateHash(plainText);
            Assert.IsFalse(CryptographyUtility.CompareBytes(providerHash1, providerHash2), "compare");
        }
Esempio n. 20
0
 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);
        }
Esempio n. 23
0
 public int GetEncryptedIntCookie(string name)
 {
     if (RequestCookies[name] != null)
     {
         return(int.Parse(CryptographyUtility.DecryptString(RequestCookies[name].Value)));
     }
     return(-1);
 }
Esempio n. 24
0
        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));
        }
Esempio n. 25
0
        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));
        }
Esempio n. 27
0
 public void SetEncryptedCookie(string name, object value)
 {
     if (value != null)
     {
         HttpCookie cookie = new HttpCookie(name, CryptographyUtility.EncryptString(value));
         cookie.Path = "/";
         ResponseCookies.Add(cookie);
     }
 }
Esempio n. 28
0
        /// <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);
        }
Esempio n. 29
0
        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);
        }
Esempio n. 30
0
 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));
     }
 }