Ejemplo n.º 1
0
        public async Task <bool> EncryptAsync(string publicKey, IList <byte> dataArray, IList <byte> localPassword)
        {
            IBuffer keyMaterial;

            //if (await KeyCredentialManager.IsSupportedAsync())
            //{
            //    var boh = await KeyCredentialManager.RequestCreateAsync(publicKey, KeyCredentialCreationOption.ReplaceExisting);
            //    if (boh.Status == KeyCredentialStatus.Success)
            //    {
            //        var boh2 = await boh.Credential.RequestSignAsync()
            //    }
            //}
            //else
            {
                var dialog = new SettingsPasscodeInputPopup();

                var confirm = await dialog.ShowQueuedAsync();

                if (confirm != ContentDialogResult.Primary)
                {
                    return(false);
                }

                var secret   = CryptographicBuffer.ConvertStringToBinary(dialog.Passcode, BinaryStringEncoding.Utf8);
                var salt     = CryptographicBuffer.GenerateRandom(32);
                var material = PBKDF2(secret, salt);

                var data = CryptographicBuffer.CreateFromByteArray(dataArray.ToArray());

                var objAlg = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcbPkcs7);
                var key    = objAlg.CreateSymmetricKey(material);

                var encrypt    = CryptographicEngine.Encrypt(key, data, null);
                var saltString = CryptographicBuffer.EncodeToHexString(salt);
                var dataString = CryptographicBuffer.EncodeToHexString(encrypt);

                var localPasswordBuffer = CryptographicBuffer.CreateFromByteArray(localPassword.ToArray());
                var localPasswordString = CryptographicBuffer.EncodeToHexString(localPasswordBuffer);

                var vault    = new PasswordVault();
                var password = $"{saltString};{dataString};{localPasswordString};{(dialog.IsSimple ? 1 : 2)}";
                vault.Add(new PasswordCredential($"{_session}", publicKey, password));
            }

            return(true);
        }
Ejemplo n.º 2
0
        private async void EditExecute()
        {
            var timeout = _passcodeService.AutolockTimeout + 0;
            var dialog  = new SettingsPasscodeInputPopup();

            dialog.IsSimple = _passcodeService.IsSimple;

            var confirm = await dialog.ShowQueuedAsync();

            if (confirm == ContentDialogResult.Primary)
            {
                var passcode = dialog.Passcode;
                var simple   = dialog.IsSimple;
                _passcodeService.Set(passcode, simple, timeout);

                InactivityHelper.Initialize(timeout);
            }
        }
Ejemplo n.º 3
0
        public async Task TogglePasscode()
        {
            if (_passcodeService.IsEnabled)
            {
                _passcodeService.Reset();
            }
            else
            {
                var timeout = _passcodeService.AutolockTimeout + 0;
                var dialog  = new SettingsPasscodeInputPopup();
                dialog.IsSimple = _passcodeService.IsSimple;

                var confirm = await dialog.ShowQueuedAsync();

                if (confirm == ContentDialogResult.Primary)
                {
                    var passcode = dialog.Passcode;
                    var simple   = dialog.IsSimple;
                    _passcodeService.Set(passcode, simple, timeout);

                    InactivityHelper.Initialize(timeout);
                }
            }
        }