Skip to content

A Swiss Army knife for developers.

Fix for incorrect base64 hashes (#397)

Anirudh Khannab024f5de4f84
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 9dd32edbd..dfaa184ed 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 @@ namespace DevToys.ViewModels.Tools.HashGenerator
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 572f5e4a2..c54eacbef 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 @@
<FontIcon Glyph="&#xF7B2;" />
</controls:ExpandableSettingControl.Icon>
<ToggleSwitch
+ x:Name="IsUppercaseToggleSwitch"
Style="{StaticResource RightAlignedToggleSwitchStyle}"
IsOn="{x:Bind ViewModel.IsUppercase, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</controls:ExpandableSettingControl>
@@ -35,7 +36,8 @@
</controls:ExpandableSettingControl.Icon>
<ComboBox
SelectedValuePath="Tag"
- SelectedValue="{x:Bind ViewModel.OutputType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
+ SelectedValue="{x:Bind ViewModel.OutputType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+ SelectionChanged="OutputType_SelectionChanged">
<ComboBoxItem Tag="Hex" Content="{x:Bind ViewModel.Strings.OutputHex}" />
<ComboBoxItem Tag="Base64" Content="{x:Bind ViewModel.Strings.OutputBase64}"/>
</ComboBox>
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 eef81917b..c5a34b5d2 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 @@ namespace DevToys.Views.Tools.HashGenerator
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;
+ }
+ }
}
}