From 01901c346acb46925a5ee40cf3cd4b8e64d27e6a Mon Sep 17 00:00:00 2001 From: Anirudh Khanna Date: Wed, 16 Feb 2022 01:12:29 +0530 Subject: [PATCH] Fix for incorrect base64 hashes --- .../HashGenerator/HashGeneratorToolViewModel.cs | 14 ++++---------- .../HashGenerator/HashGeneratorToolPage.xaml | 4 +++- .../HashGenerator/HashGeneratorToolPage.xaml.cs | 12 ++++++++++++ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/dev/impl/DevToys/ViewModels/Tools/Generators/HashGenerator/HashGeneratorToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/Generators/HashGenerator/HashGeneratorToolViewModel.cs index 9dd32edbdb..dfaa184ed0 100644 --- a/src/dev/impl/DevToys/ViewModels/Tools/Generators/HashGenerator/HashGeneratorToolViewModel.cs +++ b/src/dev/impl/DevToys/ViewModels/Tools/Generators/HashGenerator/HashGeneratorToolViewModel.cs @@ -190,21 +190,15 @@ private async Task CalculateHashAsync(string alrogithmName, string text) string? hash=""; if (string.Equals(OutputType, HexOutput)) { - hash = CryptographicBuffer.EncodeToHexString(buffer); + hash = IsUppercase + ? CryptographicBuffer.EncodeToHexString(buffer).ToUpperInvariant() + : CryptographicBuffer.EncodeToHexString(buffer).ToLowerInvariant(); } else if (string.Equals(OutputType, Base64Output)) { hash = CryptographicBuffer.EncodeToBase64String(buffer); } - - if (IsUppercase) - { - return hash.ToUpperInvariant(); - } - else - { - return hash.ToLowerInvariant(); - } + return hash; } catch (Exception ex) { diff --git a/src/dev/impl/DevToys/Views/Tools/Generators/HashGenerator/HashGeneratorToolPage.xaml b/src/dev/impl/DevToys/Views/Tools/Generators/HashGenerator/HashGeneratorToolPage.xaml index 572f5e4a28..c54eacbef3 100644 --- a/src/dev/impl/DevToys/Views/Tools/Generators/HashGenerator/HashGeneratorToolPage.xaml +++ b/src/dev/impl/DevToys/Views/Tools/Generators/HashGenerator/HashGeneratorToolPage.xaml @@ -24,6 +24,7 @@ @@ -35,7 +36,8 @@ + SelectedValue="{x:Bind ViewModel.OutputType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" + SelectionChanged="OutputType_SelectionChanged"> diff --git a/src/dev/impl/DevToys/Views/Tools/Generators/HashGenerator/HashGeneratorToolPage.xaml.cs b/src/dev/impl/DevToys/Views/Tools/Generators/HashGenerator/HashGeneratorToolPage.xaml.cs index eef81917bf..c5a34b5d21 100644 --- a/src/dev/impl/DevToys/Views/Tools/Generators/HashGenerator/HashGeneratorToolPage.xaml.cs +++ b/src/dev/impl/DevToys/Views/Tools/Generators/HashGenerator/HashGeneratorToolPage.xaml.cs @@ -46,5 +46,17 @@ protected override void OnNavigatedTo(NavigationEventArgs e) base.OnNavigatedTo(e); } + + private void OutputType_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + if ((sender as ComboBox)?.SelectedValue as string == "Base64") + { + IsUppercaseToggleSwitch.IsEnabled = false; + } + else + { + IsUppercaseToggleSwitch.IsEnabled = true; + } + } } }