示例#1
0
        private void EncryptDictionary(BlockingCollection <string> collection,
                                       BlockingCollection <Tuple <string, byte[]> > encryptedCollectionInBytes)
        {
            while (!collection.IsCompleted)
            {
                string str;
                try
                {
                    str = collection.Take();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Cannot take from already completed collection!");
                    Console.WriteLine("----------------");
                    Console.WriteLine();
                    Console.WriteLine("----------------");
                    break;
                }

                char[] charArray         = str.ToCharArray();
                byte[] passwordAsBytes   = Array.ConvertAll(charArray, PasswordFileHandler.GetConverter());
                byte[] encryptedPassword = _messageDigest.ComputeHash(passwordAsBytes);

                try
                {
                    encryptedCollectionInBytes.Add(new Tuple <string, byte[]>(str, encryptedPassword));
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine("All items are already Encrypted! Finishing this thread!");
                    break;
                }
            }
            encryptedCollectionInBytes.CompleteAdding();
        }
示例#2
0
        /// <summary>
        /// Checks a single word (or rather a variation of a word): Encrypts and compares to an entry in the password file
        /// </summary>
        /// <param name="userInfo">Username, encrypted password from the password file</param>
        /// <param name="possiblePassword">Username, encrypted password pair from the password file</param>
        private void CheckSingleWord(UserInfo userInfo, String possiblePassword)
        {
            char[] charArray       = possiblePassword.ToCharArray();
            byte[] passwordAsBytes = Array.ConvertAll(charArray, PasswordFileHandler.GetConverter());

            byte[] encryptedPassword = _messageDigest.ComputeHash(passwordAsBytes);

            if (CompareBytes(userInfo.EntryptedPassword, encryptedPassword))  //compares byte arrays
            {
                _result = new UserInfoClearText(userInfo.Username, possiblePassword);
                //Console.WriteLine(userInfo.Username + " " + possiblePassword);
            }
        }
示例#3
0
        /// <summary>
        /// Checks a single word (or rather a variation of a word): Encrypts and compares to all entries in the password file
        /// </summary>
        /// <param name="userInfos"></param>
        /// <param name="possiblePassword">List of (username, encrypted password) pairs from the password file</param>
        /// <returns>A list of (username, readable password) pairs. The list might be empty</returns>
        private IEnumerable <UserInfoClearText> CheckSingleWord(IEnumerable <UserInfo> userInfos, String possiblePassword)
        {
            char[] charArray         = possiblePassword.ToCharArray();
            byte[] passwordAsBytes   = Array.ConvertAll(charArray, PasswordFileHandler.GetConverter());
            byte[] encryptedPassword = _messageDigest.ComputeHash(passwordAsBytes);
            //string encryptedPasswordBase64 = System.Convert.ToBase64String(encryptedPassword);

            List <UserInfoClearText> results = new List <UserInfoClearText>();

            foreach (UserInfo userInfo in userInfos)
            {
                if (CompareBytes(userInfo.EntryptedPassword, encryptedPassword))
                {
                    results.Add(new UserInfoClearText(userInfo.Username, possiblePassword));
                    Console.WriteLine(userInfo.Username + " " + possiblePassword);
                }
            }
            return(results);
        }
        /// <summary>
        /// Checks a single word (or rather a variation of a word): Encrypts and compares to all entries in the password file
        /// </summary>
        /// <param name="userInfos"></param>
        /// <param name="possiblePassword">List of (username, encrypted password) pairs from the password file</param>
        /// <param name="hashes">Passed by ref to change the value</param>
        /// <returns>A list of (username, readable password) pairs. The list might be empty</returns>
        private IList <FullUser> CheckSingleWord(IList <UserInfo> userInfos, string possiblePassword, ref int hashes)
        {
            char[] charArray         = possiblePassword.ToCharArray();
            byte[] passwordAsBytes   = Array.ConvertAll(charArray, PasswordFileHandler.GetConverter());
            byte[] encryptedPassword = HashAlgorithm.ComputeHash(passwordAsBytes);
            hashes++;
            //string encryptedPasswordBase64 = System.Convert.ToBase64String(encryptedPassword);

            List <FullUser> results = new List <FullUser>();

            foreach (UserInfo userInfo in userInfos)
            {
                if (CompareBytes(userInfo.EntryptedPassword, encryptedPassword))
                {
                    results.Add(new FullUser(userInfo, possiblePassword));
                    Console.WriteLine(userInfo.Username + " " + possiblePassword);
                }
            }
            FilterWhatsDone(userInfos, results);
            return(results);
        }