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 SettingsPasscodeInputView(); 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); }
private async void EditExecute() { var timeout = _passcodeService.AutolockTimeout + 0; var dialog = new SettingsPasscodeInputView(); 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); } }