Esempio n. 1
0
        public bool Process()
        {
            Boolean retVal = false;

            try
            {
                _state = Common.NodeState.Processing;
                SCrypt scrypt = new SCrypt(Iterations.Value, BlockSize.Value, ThreadCount.Value);
                byte[] saltOut;
                byte[] bytes = scrypt.DeriveBytes((String)_password.Value, _salt.Value, out saltOut);
                _derivedKey.SetValue(bytes);
                retVal = true;
            }
            finally
            {
                _state = Common.NodeState.Processed;
                if (retVal)
                {
                    Processed?.Invoke(this, EventArgs.Empty);
                }
            }
            if (retVal)
            {
                if (_next != null && _next.Length > 0)
                {
                    return(_next[0].Process());
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        private Tuple <bool, TimeSpan> TestPasswordDerivationFunction(int count)
        {
            TimeSpan elapsed = new TimeSpan(0);
            bool     success = false;

            try
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    TestSettingsButtonText = "Please Wait...";
                    View.IsEnabled         = false;
                });
                Stopwatch stopWatch = new Stopwatch();
                string    password  = "";
                byte[]    salt      = new byte[16];
                if (PBKDF2Enabled)
                {
                    Rfc2898DeriveBytes pbkd2f = new Rfc2898DeriveBytes(
                        password,
                        salt,
                        int.Parse(PBKDF2IterationCount));

                    stopWatch.Restart();
                    int curKey = 1;
                    while (curKey < count)
                    {
                        byte[] result = pbkd2f.GetBytes(32);
                        curKey += 1;
                    }
                    elapsed = stopWatch.Elapsed;
                    success = true;
                }
                else
                {
                    SCrypt scrypt = new SCrypt(
                        int.Parse(SCryptIterationCount),
                        int.Parse(SCryptBlockSize),
                        int.Parse(SCryptThreadCount));

                    byte[] saltUsed = null;
                    stopWatch.Restart();
                    int curKey = 1;
                    while (curKey < count)
                    {
                        byte[] result = scrypt.DeriveBytes(
                            password,
                            salt,
                            out saltUsed);
                        curKey += 1;
                    }
                    elapsed = stopWatch.Elapsed;
                    success = true;
                }
            }
            finally
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    TestSettingsButtonText = "Test Settings";
                    View.IsEnabled         = true;
                });
            }
            return(new Tuple <bool, TimeSpan>(success, elapsed));
        }