Skip to content

A Swiss Army knife for developers.

Ported Certificate Decoder to DevToys 2.0 (#1033)

Etienne BAUDOUX495db7dee4f7
diff --git a/assets/font/CertificateEncoderDecoder.svg b/assets/font/CertificateEncoderDecoder.svg
new file mode 100644
index 000000000..1b293b7fe
--- /dev/null
+++ b/assets/font/CertificateEncoderDecoder.svg
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ version="1.1"
+ viewBox="-10 0 689.33333 682.66666"
+ width="1034"
+ height="1024"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <path
+ class="clr-i-outline clr-i-outline-path-1"
+ d="m 75.660938,96.827607 a 37.037036,37.037036 0 0 0 -37.03613,37.036133 v 370.37109 a 37.037036,37.037036 0 0 0 37.03613,37.03613 H 353.43925 l 10.555,-12.96224 17.22168,-21.11167 -1.66666,-2.96222 H 75.660938 V 133.86374 H 594.1798 v 158.51888 a 155.74074,155.74074 0 0 1 37.03613,33.51888 V 133.86374 A 37.037036,37.037036 0 0 0 594.1798,96.827607 Z M 131.21594,207.93764 v 29.63053 h 314.81607 v -29.63053 z m 0,74.07388 v 29.63054 h 203.70442 v -29.63054 z m 378.84927,22.77832 a 117.77777,117.77777 0 0 0 -81.44042,203.70442 l -35.92611,43.88835 16.66666,66.85222 67.7767,-82.59278 a 115.92592,115.92592 0 0 0 65.74056,0 l 67.77831,82.59278 16.66667,-66.85222 -35.92611,-43.88835 A 117.77777,117.77777 0 0 0 510.10591,304.78984 Z m 2.63346,38.17057 a 79.814813,79.814813 0 0 1 78.33333,79.7933 80.555553,80.555553 0 0 1 -80.92609,79.81446 79.814813,79.814813 0 1 1 2.59276,-159.60776 z m -381.48273,68.68165 v 29.6289 h 185.18553 v -29.6289 z"
+ style="stroke-width:18.5185" />
+</svg>
diff --git a/assets/font/DevToys-Tools-Icons.sfd b/assets/font/DevToys-Tools-Icons.sfd
index 765138753..a7d4bc0c9 100644
--- a/assets/font/DevToys-Tools-Icons.sfd
+++ b/assets/font/DevToys-Tools-Icons.sfd
@@ -22,7 +22,7 @@ OS2Version: 0
OS2_WeightWidthSlopeOnly: 0
OS2_UseTypoMetrics: 1
CreationTime: 1642371451
-ModificationTime: 1657684840
+ModificationTime: 1688570565
PfmFamily: 17
TTFWeight: 400
TTFWidth: 5
@@ -51,11 +51,11 @@ NameList: AGL For New Fonts
DisplaySize: -48
AntiAlias: 1
FitToEm: 0
-WinInfo: 0 38 14
+WinInfo: 0 33 12
BeginPrivate: 0
EndPrivate
TeXData: 1 0 0 346030 173015 115343 0 1048576 115343 783286 444596 497025 792723 393216 433062 380633 303038 157286 324010 404750 52429 2506097 1059062 262144
-BeginChars: 291 35
+BeginChars: 310 37
StartChar: Base64EncoderDecoder
Encoding: 256 256 0
@@ -3134,5 +3134,168 @@ SplineSet
EndSplineSet
Validated: 1
EndChar
+
+StartChar: Certificate
+Encoding: 291 309 35
+Width: 1024
+Flags: H
+LayerCount: 2
+Fore
+SplineSet
+195 413 m 1
+ 470 413 l 1
+ 470 368 l 1
+ 195 368 l 1
+ 195 413 l 1
+762 515 m 0
+ 761 515 760 515 759 515 c 0
+ 694 515 641 461 641 396 c 0
+ 641 331 693 278 758 277 c 0
+ 824 277 877 330 878 396 c 0
+ 878 461 826 514 762 515 c 0
+758 571 m 1
+ 759 571 l 2
+ 856 571 934 493 934 396 c 0
+ 934 346 913 301 879 269 c 1
+ 932 203 l 1
+ 907 104 l 1
+ 806 227 l 1
+ 791 222 775 220 758 220 c 0
+ 741 220 724 222 709 227 c 1
+ 608 104 l 1
+ 583 203 l 1
+ 637 269 l 1
+ 603 301 581 346 581 396 c 0
+ 581 493 659 571 756 571 c 2
+ 758 571 l 1
+195 605 m 1
+ 498 605 l 1
+ 498 561 l 1
+ 195 561 l 1
+ 195 605 l 1
+195 715 m 1
+ 663 715 l 1
+ 663 671 l 1
+ 195 671 l 1
+ 195 715 l 1
+112 880 m 2
+ 883 880 l 2
+ 913 880 938 855 938 825 c 2
+ 938 540 l 1
+ 922 560 904 576 883 590 c 1
+ 883 825 l 1
+ 112 825 l 1
+ 112 275 l 1
+ 564 275 l 1
+ 566 271 l 1
+ 541 239 l 1
+ 525 220 l 1
+ 112 220 l 2
+ 82 220 57 245 57 275 c 2
+ 57 825 l 2
+ 57 855 82 880 112 880 c 2
+EndSplineSet
+Validated: 1
+EndChar
+
+StartChar: PasswordGenerator
+Encoding: 292 310 36
+Width: 1024
+Flags: H
+LayerCount: 2
+Fore
+SplineSet
+502 580 m 2
+ 532 549 l 1
+ 563 580 l 2
+ 570 587 577 590 585 590 c 0
+ 588 590 592 590 595 589 c 0
+ 607 586 614 577 617 565 c 0
+ 618 562 618 558 618 555 c 0
+ 618 547 616 541 610 535 c 2
+ 580 504 l 1
+ 610 473 l 2
+ 615 466 618 459 618 451 c 0
+ 618 443 615 435 609 428 c 0
+ 603 421 596 418 587 418 c 0
+ 578 418 570 421 563 428 c 2
+ 532 459 l 1
+ 502 428 l 2
+ 496 421 489 418 481 418 c 0
+ 478 418 474 418 471 419 c 0
+ 459 422 452 430 449 442 c 0
+ 448 445 448 448 448 451 c 0
+ 448 459 451 467 457 473 c 2
+ 487 504 l 1
+ 457 535 l 2
+ 452 542 449 549 449 557 c 0
+ 449 565 452 573 458 579 c 0
+ 464 585 471 588 480 588 c 0
+ 489 588 497 585 502 580 c 2
+223 580 m 0
+ 228 587 236 590 245 590 c 0
+ 254 590 261 587 268 580 c 2
+ 299 549 l 1
+ 330 580 l 2
+ 336 587 342 590 350 590 c 0
+ 353 590 357 590 360 589 c 0
+ 372 586 381 577 384 565 c 0
+ 385 562 385 558 385 555 c 0
+ 385 547 382 541 375 535 c 2
+ 344 504 l 1
+ 375 473 l 2
+ 382 466 385 459 385 451 c 0
+ 385 443 382 435 375 428 c 0
+ 368 421 360 418 351 418 c 0
+ 342 418 335 421 330 428 c 2
+ 299 459 l 1
+ 268 428 l 2
+ 261 423 254 420 246 420 c 0
+ 238 420 230 423 224 429 c 0
+ 218 435 215 443 214 451 c 0
+ 213 459 216 466 223 473 c 2
+ 254 504 l 1
+ 223 535 l 2
+ 216 542 213 549 213 558 c 0
+ 213 567 216 575 223 580 c 0
+705 440 m 2
+ 778 440 l 2
+ 788 440 796 437 802 431 c 0
+ 808 425 811 418 811 409 c 0
+ 811 400 808 392 802 386 c 0
+ 796 380 788 376 778 375 c 2
+ 705 375 l 2
+ 695 375 687 378 681 385 c 0
+ 675 392 672 400 672 409 c 0
+ 672 418 675 425 681 431 c 0
+ 687 437 695 440 705 440 c 2
+223 803 m 2
+ 801 803 l 2
+ 839 803 871 789 898 762 c 0
+ 925 735 938 702 938 664 c 2
+ 938 344 l 2
+ 938 306 925 273 898 246 c 0
+ 871 219 839 205 801 205 c 2
+ 223 205 l 2
+ 185 205 153 219 126 246 c 0
+ 99 273 86 306 86 344 c 2
+ 86 664 l 2
+ 86 702 99 735 126 762 c 0
+ 153 789 185 803 223 803 c 2
+150 664 m 2
+ 150 344 l 2
+ 150 324 157 306 171 291 c 0
+ 185 276 203 268 223 268 c 2
+ 801 268 l 2
+ 821 268 839 276 853 291 c 0
+ 867 306 874 324 874 344 c 2
+ 874 664 l 2
+ 874 684 867 702 853 717 c 0
+ 839 732 821 739 801 739 c 2
+ 223 739 l 2
+ 203 739 185 732 171 717 c 0
+ 157 702 150 684 150 664 c 2
+EndSplineSet
+EndChar
EndChars
EndSplineFont
diff --git a/assets/font/DevToys-Tools-Icons.ttf b/assets/font/DevToys-Tools-Icons.ttf
index ab374a63d..64edbcac0 100644
Binary files a/assets/font/DevToys-Tools-Icons.ttf and b/assets/font/DevToys-Tools-Icons.ttf differ
diff --git a/assets/font/README.md b/assets/font/README.md
index da84478b2..c3679f2ad 100644
--- a/assets/font/README.md
+++ b/assets/font/README.md
@@ -9,13 +9,14 @@ We use FontForge to generate the font. Here is a small tutorial:
1. Install [FontForge](https://fontforge.org/en-US/) and open [DevToys-Tools-Icons.sfd](/assets/font/DevToys-Tools-Icons.sfd).
2. In Figma, Inkscape, Adobe Illustrator or else, create a glyph and export it as a SVG.
3. In FontForge, go to `Encoding > Add Encoding Slots`.
-4. Select the slot you just created and go to `File > Import` and select the SVG you want to import.
+4. Select the slot you just created and go to `File > Import` and select the SVG you want to import. Under `Options`, uncheck `Scale to fit (Misc)`.
5. Then, go to `Element > Glyph Info` and set a glyph name and Unicode value like `U+0100`.
# Generate a TrueType font
1. First, we need to validate the change we made. Go to `Element > Validation > Validate...`
-2. Typical error we encountered in the past is `Self Intersecting`. You can resolve it automatically by using `Element > Overlap > Remove Overlap`. If it made the glyph ugly, you will have to fix the issue manually by editing the SVG.
-3. Another typical error we encountered is `Non-Integral Coordinates`. To fix it automatically, use `Element > Round > To Int`.
-4. Once there are no validation issues anymore, go to `File > Generate Fonts`. Select `TrueType` and check `Validate before saving`. Then click `Generate`.
-5. A TTF file should be generated. You can verify that it works well by trying to open it in the app [Character Map UWP](https://apps.microsoft.com/store/detail/character-map-uwp/9WZDNCRDXF41?hl=en-us&gl=us).
+ * Typical error we encountered in the past is `Self Intersecting`. You can resolve it automatically by using `Element > Overlap > Remove Overlap`. If it made the glyph ugly, you will have to fix the issue manually by editing the SVG.
+ * Another typical error we encountered is `Non-Integral Coordinates`. To fix it automatically, use `Element > Round > To Int`.
+ * Another error is `Missing Points at Extrema`. To fix it, use `Element > Add Extrema`.
+2. Once there are no validation issues anymore, go to `File > Generate Fonts`. Select `TrueType` and check `Validate before saving`. Then click `Generate`.
+3. A TTF file should be generated. You can verify that it works well by trying to open it in the app [Character Map UWP](https://apps.microsoft.com/store/detail/character-map-uwp/9WZDNCRDXF41?hl=en-us&gl=us).
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIPasswordInput.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIPasswordInput.cs
new file mode 100644
index 000000000..461066f48
--- /dev/null
+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIPasswordInput.cs
@@ -0,0 +1,38 @@
+namespace DevToys.Api;
+
+/// <summary>
+/// A component that can be used to display or edit passwords on a single line.
+/// </summary>
+public interface IUIPasswordInput : IUISingleLineTextInput
+{
+}
+
+[DebuggerDisplay($"Id = {{{nameof(Id)}}}, Text = {{{nameof(Text)}}}")]
+internal class UIPasswordInput : UISingleLineTextInput, IUIPasswordInput
+{
+
+ internal UIPasswordInput(string? id)
+ : base(id)
+ {
+ }
+}
+
+public static partial class GUI
+{
+ /// <summary>
+ /// A component that can be used to display or edit passwords on a single line.
+ /// </summary>
+ public static IUIPasswordInput PasswordInput()
+ {
+ return PasswordInput(null);
+ }
+
+ /// <summary>
+ /// A component that can be used to display or edit passwords on a single line.
+ /// </summary>
+ /// <param name="id">An optional unique identifier for this UI element.</param>
+ public static IUIPasswordInput PasswordInput(string? id)
+ {
+ return new UIPasswordInput(id);
+ }
+}
diff --git a/src/app/dev/DevToys.Blazor/Components/Text/TextBox/TextBox.razor b/src/app/dev/DevToys.Blazor/Components/Text/TextBox/TextBox.razor
index 164341875..fd0b6589e 100644
--- a/src/app/dev/DevToys.Blazor/Components/Text/TextBox/TextBox.razor
+++ b/src/app/dev/DevToys.Blazor/Components/Text/TextBox/TextBox.razor
@@ -39,7 +39,7 @@
placeholder="@Placeholder"
disabled="@(!IsActuallyEnabled)"
readonly="@(IsReadOnly)"
- type="@(Type.ToString().ToLowerInvariant())"
+ type="@(_internalType.ToString().ToLowerInvariant())"
min="@Min.ToString("F0")"
max="@Max.ToString("F0")"
step="@Step"
@@ -54,14 +54,28 @@
{
if (!string.IsNullOrEmpty(Text))
{
- <Button Appearance="ButtonAppearance.Stealth"
- Class="text-box-clear-button"
- HorizontalAlignment="UIHorizontalAlignment.Right"
- title="@DevToys.Localization.Strings.TextBox.TextBox.Clear"
- aria-label="@DevToys.Localization.Strings.TextBox.TextBox.Clear"
- @onclick="OnClearClick">
- <FontIcon Glyph="@('\uF369')" />
- </Button>
+ if (Type == TextBoxTypes.Password)
+ {
+ <Button Appearance="ButtonAppearance.Stealth"
+ HorizontalAlignment="UIHorizontalAlignment.Right"
+ title="@DevToys.Localization.Strings.TextBox.TextBox.RevealPassword"
+ aria-label="@DevToys.Localization.Strings.TextBox.TextBox.RevealPassword"
+ @onmousedown="OnRevealPasswordMouseDown"
+ @onmouseup="OnRevealPasswordMouseUp">
+ <FontIcon Glyph="@('\uE5F2')" />
+ </Button>
+ }
+ else
+ {
+ <Button Appearance="ButtonAppearance.Stealth"
+ Class="text-box-clear-button"
+ HorizontalAlignment="UIHorizontalAlignment.Right"
+ title="@DevToys.Localization.Strings.TextBox.TextBox.Clear"
+ aria-label="@DevToys.Localization.Strings.TextBox.TextBox.Clear"
+ @onclick="OnClearClick">
+ <FontIcon Glyph="@('\uF369')" />
+ </Button>
+ }
}
if (Type == TextBoxTypes.Number)
diff --git a/src/app/dev/DevToys.Blazor/Components/Text/TextBox/TextBox.razor.cs b/src/app/dev/DevToys.Blazor/Components/Text/TextBox/TextBox.razor.cs
index 135348c7d..766c25db2 100644
--- a/src/app/dev/DevToys.Blazor/Components/Text/TextBox/TextBox.razor.cs
+++ b/src/app/dev/DevToys.Blazor/Components/Text/TextBox/TextBox.razor.cs
@@ -40,6 +40,7 @@ public partial class TextBox : MefComponentBase, IFocusable
private InputText? _input;
private bool _isContextMenuOpened;
private int _textChangedCount;
+ private TextBoxTypes _internalType = TextBoxTypes.Text;
protected override string JavaScriptFile => "./_content/DevToys.Blazor/Components/Text/TextBox/TextBox.razor.js";
@@ -99,6 +100,13 @@ public partial class TextBox : MefComponentBase, IFocusable
_settingsProvider.SettingChanged += SettingsProvider_SettingChanged;
}
+ protected override void OnParametersSet()
+ {
+ _internalType = Type;
+
+ base.OnParametersSet();
+ }
+
public ValueTask<bool> FocusAsync()
{
Guard.IsNotNull(_input);
@@ -175,6 +183,17 @@ public partial class TextBox : MefComponentBase, IFocusable
FocusAsync();
}
+ private void OnRevealPasswordMouseDown()
+ {
+ _internalType = TextBoxTypes.Text;
+ }
+
+ private void OnRevealPasswordMouseUp()
+ {
+ _internalType = Type;
+ FocusAsync();
+ }
+
private async Task OnDecreaseClickAsync()
{
using (await Semaphore.WaitAsync(CancellationToken.None))
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor b/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor
index 7b498ef11..a278f2f37 100644
--- a/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UIElementPresenter.razor
@@ -58,6 +58,10 @@
<UIMultiLineTextInputPresenter UIMultiLineTextInput="@multiLineTextInput" />
break;
+ case IUIPasswordInput passwordInput:
+ <UIPasswordInputPresenter UIPasswordInput="@passwordInput" />
+ break;
+
case IUINumberInput numberInput:
<UINumberInputPresenter UINumberInput="@numberInput" />
break;
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UIPasswordInputPresenter.razor b/src/app/dev/DevToys.Blazor/Components/UIElements/UIPasswordInputPresenter.razor
new file mode 100644
index 000000000..a29f5e925
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UIPasswordInputPresenter.razor
@@ -0,0 +1,13 @@
+@namespace DevToys.Blazor.Components.UIElements
+@using DevToys.Api;
+@inherits StyledComponentBase
+
+<UITextInputWrapper @ref="_textInputWrapper" UITextInput="@UIPasswordInput">
+ <TextBox IsVisible="@UIPasswordInput.IsVisible"
+ IsEnabled="@(UIPasswordInput.IsEnabled && IsActuallyEnabled)"
+ Text="@UIPasswordInput.Text"
+ IsReadOnly="@UIPasswordInput.IsReadOnly"
+ TextChanged="@OnTextChanged"
+ Type="TextBoxTypes.Password"
+ ParentComponent="_textInputWrapper" />
+</UITextInputWrapper>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UIPasswordInputPresenter.razor.cs b/src/app/dev/DevToys.Blazor/Components/UIElements/UIPasswordInputPresenter.razor.cs
new file mode 100644
index 000000000..e5ef95806
--- /dev/null
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UIPasswordInputPresenter.razor.cs
@@ -0,0 +1,14 @@
+namespace DevToys.Blazor.Components.UIElements;
+
+public partial class UIPasswordInputPresenter : StyledComponentBase
+{
+ private UITextInputWrapper _textInputWrapper = default!;
+
+ [Parameter]
+ public IUIPasswordInput UIPasswordInput { get; set; } = default!;
+
+ private void OnTextChanged(string newText)
+ {
+ UIPasswordInput.Text(newText);
+ }
+}
diff --git a/src/app/dev/DevToys.Localization/Strings/TextBox/TextBox.Designer.cs b/src/app/dev/DevToys.Localization/Strings/TextBox/TextBox.Designer.cs
index 8c7ac4d67..bfaeda90c 100644
--- a/src/app/dev/DevToys.Localization/Strings/TextBox/TextBox.Designer.cs
+++ b/src/app/dev/DevToys.Localization/Strings/TextBox/TextBox.Designer.cs
@@ -114,6 +114,15 @@ namespace DevToys.Localization.Strings.TextBox {
}
}
+ /// <summary>
+ /// Looks up a localized string similar to Reveal.
+ /// </summary>
+ public static string RevealPassword {
+ get {
+ return ResourceManager.GetString("RevealPassword", resourceCulture);
+ }
+ }
+
/// <summary>
/// Looks up a localized string similar to Select All.
/// </summary>
diff --git a/src/app/dev/DevToys.Localization/Strings/TextBox/TextBox.resx b/src/app/dev/DevToys.Localization/Strings/TextBox/TextBox.resx
index 87bcf48b6..a744b8ebe 100644
--- a/src/app/dev/DevToys.Localization/Strings/TextBox/TextBox.resx
+++ b/src/app/dev/DevToys.Localization/Strings/TextBox/TextBox.resx
@@ -135,6 +135,9 @@
<data name="Paste" xml:space="preserve">
<value>Paste</value>
</data>
+ <data name="RevealPassword" xml:space="preserve">
+ <value>Reveal</value>
+ </data>
<data name="SelectAll" xml:space="preserve">
<value>Select All</value>
</data>
diff --git a/src/app/dev/DevToys.Tools/DevToys.Tools.csproj b/src/app/dev/DevToys.Tools/DevToys.Tools.csproj
index 9b35e645b..b688b2b1a 100644
--- a/src/app/dev/DevToys.Tools/DevToys.Tools.csproj
+++ b/src/app/dev/DevToys.Tools/DevToys.Tools.csproj
@@ -38,6 +38,11 @@
<AutoGen>True</AutoGen>
<DependentUpon>GlobalStrings.resx</DependentUpon>
</Compile>
+ <Compile Update="Tools\EncodersDecoders\Certificate\CertificateDecoder.Designer.cs">
+ <DesignTime>True</DesignTime>
+ <AutoGen>True</AutoGen>
+ <DependentUpon>CertificateDecoder.resx</DependentUpon>
+ </Compile>
<Compile Update="Tools\Formatters\Json\JsonFormatter.Designer.cs">
<DependentUpon>JsonFormatter.resx</DependentUpon>
<DesignTime>True</DesignTime>
@@ -203,6 +208,10 @@
<LastGenOutput>JsonTableConverter.Designer.cs</LastGenOutput>
<Generator>ResXFileCodeGenerator</Generator>
</EmbeddedResource>
+ <EmbeddedResource Update="Tools\EncodersDecoders\Certificate\CertificateDecoder.resx">
+ <Generator>ResXFileCodeGenerator</Generator>
+ <LastGenOutput>CertificateDecoder.Designer.cs</LastGenOutput>
+ </EmbeddedResource>
<EmbeddedResource Update="Tools\Formatters\Json\JsonFormatter.resx">
<LastGenOutput>JsonFormatter.Designer.cs</LastGenOutput>
<Generator>ResXFileCodeGenerator</Generator>
diff --git a/src/app/dev/DevToys.Tools/Helpers/CertificateHelper.cs b/src/app/dev/DevToys.Tools/Helpers/CertificateHelper.cs
new file mode 100644
index 000000000..994ef96e9
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/Helpers/CertificateHelper.cs
@@ -0,0 +1,125 @@
+using System.Security.Cryptography;
+using System.Security.Cryptography.X509Certificates;
+using System.Text;
+using DevToys.Tools.Tools.EncodersDecoders.Certificate;
+using Microsoft.Extensions.Logging;
+
+namespace DevToys.Tools.Helpers;
+
+internal static class CertificateHelper
+{
+ private const string BeginCertificate = "BEGIN CERTIFICATE";
+ private const string BeginCertificateRequest = "BEGIN CERTIFICATE REQUEST";
+
+ // "The specified password is not correct." (ERROR_INVALID_PASSWORD)
+ private const int ERROR_INVALID_PASSWORD_HRESULT = unchecked((int)0x80070056);
+
+ /// <summary>
+ /// Returns the friendly formatted, decoded certificate details.
+ /// CSR format is currently not supported in UWP, but is in .NET 7 <see href="https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.x509certificates.certificaterequest.loadsigningrequest?view=net-7.0"/>
+ /// PEM format is limited by the current framework version <see href="https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.x509certificates.x509certificate2.createfrompemfile?view=net-7.0"/>
+ /// </summary>
+ /// <param name="input">Certificate data</param>
+ /// <param name="password">Password for protected private key. This should only be relevant for decoding pfx format.</param>
+ /// <returns>Certificate details</returns>
+ internal static bool TryDecodeCertificate(ILogger logger, string input, string? password, out string? decoded)
+ {
+ decoded = null;
+ string publicCert = input;
+ if (publicCert.Contains('-'))
+ {
+ string[] splitCert = input.Split('-', StringSplitOptions.RemoveEmptyEntries);
+ for (int i = 0; i < splitCert.Length; i++)
+ {
+ if (string.Equals(splitCert[i], BeginCertificate, StringComparison.OrdinalIgnoreCase))
+ {
+ publicCert = splitCert[i + 1];
+ break;
+ }
+ // If this is a valid certificate request, we should still return true with the error message
+ else if (string.Equals(splitCert[i], BeginCertificateRequest, StringComparison.OrdinalIgnoreCase))
+ {
+ decoded = CertificateDecoder.UnsupportedFormatError;
+ return false;
+ }
+ }
+ }
+
+ X509Certificate2 certificate;
+ try
+ {
+ certificate = new X509Certificate2(Convert.FromBase64String(publicCert), password);
+ decoded = certificate.ToString();
+ }
+ catch (CryptographicException wce)
+ {
+ // If this is a valid certificate, but an incorrect/missing password, we should still return true
+ if (wce.HResult == ERROR_INVALID_PASSWORD_HRESULT)
+ {
+ decoded = CertificateDecoder.InvalidPasswordError;
+ }
+
+ return false;
+ }
+ catch (Exception)
+ {
+ decoded = CertificateDecoder.UnsupportedFormatError;
+ return false;
+ }
+
+ if (!string.IsNullOrEmpty(decoded) && certificate.Extensions.OfType<X509Extension>().Any())
+ {
+ decoded = string.Join(Environment.NewLine, decoded, DecodeExtensions(logger, certificate));
+ }
+
+ return true;
+ }
+
+ private static string DecodeExtensions(ILogger logger, X509Certificate2 certificate)
+ {
+ // Try to decode the X.509 extensions.
+ try
+ {
+ StringBuilder extensionData = new();
+ foreach (X509Extension x509Extension in certificate.Extensions)
+ {
+ AsnEncodedData asnEncodedData = new(x509Extension.Oid, x509Extension.RawData);
+
+ // Add the name in brackets to match the previous output from X509Certificate.ToString()
+ extensionData.AppendLine($"[{x509Extension.Oid?.FriendlyName}]");
+
+ // Add each line of the data, indented by two spaces to match the output from X509Certificate.ToString()
+ foreach (string dataLine in asnEncodedData.Format(multiLine: true).Split(Environment.NewLine))
+ {
+ extensionData.AppendLine($" {dataLine}");
+ }
+ }
+
+ return extensionData.ToString().Trim();
+ }
+ catch (Exception ex)
+ {
+ logger.LogError(ex, "Failed to parse X.509 extensions from certificate.");
+ }
+
+ return string.Empty;
+ }
+
+ /// <summary>
+ /// Get the string data from a certificate file.
+ /// If the string is pem format with plain text values, it will return as is.
+ /// Otherwise, the base64 encoded result will be returned.
+ /// </summary>
+ /// <param name="data">Certificate data from file</param>
+ /// <returns>string result of certificate</returns>
+ internal static string GetRawCertificateString(byte[] data)
+ {
+ string value = Encoding.UTF8.GetString(data);
+ if (value.Contains(BeginCertificate, StringComparison.OrdinalIgnoreCase))
+ {
+ return value;
+ }
+
+ return Convert.ToBase64String(data);
+ }
+}
diff --git a/src/app/dev/DevToys.Tools/SmartDetection/CertificateDetector.cs b/src/app/dev/DevToys.Tools/SmartDetection/CertificateDetector.cs
new file mode 100644
index 000000000..60da295d9
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/SmartDetection/CertificateDetector.cs
@@ -0,0 +1,27 @@
+using DevToys.Tools.Helpers;
+
+namespace DevToys.Tools.SmartDetection;
+
+[Export(typeof(IDataTypeDetector))]
+[DataTypeName(InternalName, baseName: PredefinedCommonDataTypeNames.Text)]
+internal sealed class CertificateDetector : IDataTypeDetector
+{
+ internal const string InternalName = "Certificate";
+
+ public ValueTask<DataDetectionResult> TryDetectDataAsync(object rawData, DataDetectionResult? resultFromBaseDetector, CancellationToken cancellationToken)
+ {
+ if (resultFromBaseDetector is not null
+ && resultFromBaseDetector.Data is string dataString
+ && !string.IsNullOrWhiteSpace(dataString))
+ {
+ bool isCertificate = CertificateHelper.TryDecodeCertificate(this.Log(), dataString, password: null, out string? _);
+
+ if (isCertificate)
+ {
+ return ValueTask.FromResult(new DataDetectionResult(Success: true, Data: dataString));
+ }
+ }
+
+ return ValueTask.FromResult(DataDetectionResult.Unsuccessful);
+ }
+}
diff --git a/src/app/dev/DevToys.Tools/Tools/EncodersDecoders/Certificate/CertificateDecoder.Designer.cs b/src/app/dev/DevToys.Tools/Tools/EncodersDecoders/Certificate/CertificateDecoder.Designer.cs
new file mode 100644
index 000000000..89497cf5b
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/Tools/EncodersDecoders/Certificate/CertificateDecoder.Designer.cs
@@ -0,0 +1,198 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace DevToys.Tools.Tools.EncodersDecoders.Certificate {
+ using System;
+
+
+ /// <summary>
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ /// </summary>
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class CertificateDecoder {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal CertificateDecoder() {
+ }
+
+ /// <summary>
+ /// Returns the cached ResourceManager instance used by this class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DevToys.Tools.Tools.EncodersDecoders.Certificate.CertificateDecoder", typeof(CertificateDecoder).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ /// <summary>
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Certificate Decoder tool.
+ /// </summary>
+ internal static string AccessibleName {
+ get {
+ return ResourceManager.GetString("AccessibleName", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Decode a certificate.
+ /// </summary>
+ internal static string Description {
+ get {
+ return ResourceManager.GetString("Description", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Input file selected doesn&apos;t exist.
+ /// </summary>
+ internal static string InputFileNotFound {
+ get {
+ return ResourceManager.GetString("InputFileNotFound", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Raw certificate text or path to a certificate file to decode.
+ /// </summary>
+ internal static string InputOptionDescription {
+ get {
+ return ResourceManager.GetString("InputOptionDescription", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Input.
+ /// </summary>
+ internal static string InputTitle {
+ get {
+ return ResourceManager.GetString("InputTitle", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Please specify an input text or an input file.
+ /// </summary>
+ internal static string InvalidInputOrFileCommand {
+ get {
+ return ResourceManager.GetString("InvalidInputOrFileCommand", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Invalid password..
+ /// </summary>
+ internal static string InvalidPasswordError {
+ get {
+ return ResourceManager.GetString("InvalidPasswordError", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Certificate Decoder.
+ /// </summary>
+ internal static string LongDisplayTitle {
+ get {
+ return ResourceManager.GetString("LongDisplayTitle", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Path to the output file.
+ /// </summary>
+ internal static string OutputFileOptionDescription {
+ get {
+ return ResourceManager.GetString("OutputFileOptionDescription", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Output.
+ /// </summary>
+ internal static string OutputTitle {
+ get {
+ return ResourceManager.GetString("OutputTitle", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Certificate password.
+ /// </summary>
+ internal static string PasswordOptionDescription {
+ get {
+ return ResourceManager.GetString("PasswordOptionDescription", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Password.
+ /// </summary>
+ internal static string PasswordTitle {
+ get {
+ return ResourceManager.GetString("PasswordTitle", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to CER PFX PEM CRT.
+ /// </summary>
+ internal static string SearchKeywords {
+ get {
+ return ResourceManager.GetString("SearchKeywords", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Certificate.
+ /// </summary>
+ internal static string ShortDisplayTitle {
+ get {
+ return ResourceManager.GetString("ShortDisplayTitle", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Certificate Request format not currently supported..
+ /// </summary>
+ internal static string UnsupportedFormatError {
+ get {
+ return ResourceManager.GetString("UnsupportedFormatError", resourceCulture);
+ }
+ }
+ }
+}
diff --git a/src/app/dev/DevToys.Tools/Tools/EncodersDecoders/Certificate/CertificateDecoder.resx b/src/app/dev/DevToys.Tools/Tools/EncodersDecoders/Certificate/CertificateDecoder.resx
new file mode 100644
index 000000000..c4997f7a2
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/Tools/EncodersDecoders/Certificate/CertificateDecoder.resx
@@ -0,0 +1,166 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <data name="AccessibleName" xml:space="preserve">
+ <value>Certificate Decoder tool</value>
+ </data>
+ <data name="Description" xml:space="preserve">
+ <value>Decode a certificate</value>
+ </data>
+ <data name="InputFileNotFound" xml:space="preserve">
+ <value>Input file selected doesn't exist</value>
+ </data>
+ <data name="InputOptionDescription" xml:space="preserve">
+ <value>Raw certificate text or path to a certificate file to decode</value>
+ </data>
+ <data name="InputTitle" xml:space="preserve">
+ <value>Input</value>
+ </data>
+ <data name="InvalidInputOrFileCommand" xml:space="preserve">
+ <value>Please specify an input text or an input file</value>
+ </data>
+ <data name="InvalidPasswordError" xml:space="preserve">
+ <value>Invalid password.</value>
+ </data>
+ <data name="LongDisplayTitle" xml:space="preserve">
+ <value>Certificate Decoder</value>
+ </data>
+ <data name="OutputFileOptionDescription" xml:space="preserve">
+ <value>Path to the output file</value>
+ </data>
+ <data name="OutputTitle" xml:space="preserve">
+ <value>Output</value>
+ </data>
+ <data name="PasswordOptionDescription" xml:space="preserve">
+ <value>Certificate password</value>
+ </data>
+ <data name="PasswordTitle" xml:space="preserve">
+ <value>Password</value>
+ </data>
+ <data name="SearchKeywords" xml:space="preserve">
+ <value>CER PFX PEM CRT</value>
+ <comment>Alternative search keywords.</comment>
+ </data>
+ <data name="ShortDisplayTitle" xml:space="preserve">
+ <value>Certificate</value>
+ </data>
+ <data name="UnsupportedFormatError" xml:space="preserve">
+ <value>Certificate Request format not currently supported.</value>
+ </data>
+</root>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Tools/Tools/EncodersDecoders/Certificate/CertificateDecoderCommandLineTool.cs b/src/app/dev/DevToys.Tools/Tools/EncodersDecoders/Certificate/CertificateDecoderCommandLineTool.cs
new file mode 100644
index 000000000..09b22d804
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/Tools/EncodersDecoders/Certificate/CertificateDecoderCommandLineTool.cs
@@ -0,0 +1,100 @@
+using DevToys.Tools.Helpers;
+using Microsoft.Extensions.Logging;
+using OneOf;
+
+namespace DevToys.Tools.Tools.EncodersDecoders.Certificate;
+
+[Export(typeof(ICommandLineTool))]
+[Name("CertificateDecoder")]
+[CommandName(
+ Name = "certificate",
+ Alias = "cert",
+ ResourceManagerBaseName = "DevToys.Tools.Tools.EncodersDecoders.Certificate.CertificateDecoder",
+ DescriptionResourceName = nameof(CertificateDecoder.Description))]
+internal sealed class CertificateDecoderCommandLineTool : ICommandLineTool
+{
+#pragma warning disable IDE0044 // Add readonly modifier
+ [Import]
+ private IFileStorage _fileStorage = null!;
+#pragma warning restore IDE0044 // Add readonly modifier
+
+ [CommandLineOption(
+ Name = "input",
+ Alias = "i",
+ IsRequired = true,
+ DescriptionResourceName = nameof(CertificateDecoder.InputOptionDescription))]
+ internal OneOf<FileInfo, string>? Input { get; set; }
+
+ [CommandLineOption(
+ Name = "pwd",
+ Alias = "p",
+ DescriptionResourceName = nameof(CertificateDecoder.InputOptionDescription))]
+ internal string? Password { get; set; }
+
+ [CommandLineOption(
+ Name = "outputFile",
+ Alias = "o",
+ DescriptionResourceName = nameof(CertificateDecoder.OutputFileOptionDescription))]
+ private FileInfo? OutputFile { get; set; }
+
+ public async ValueTask<int> InvokeAsync(ILogger logger, CancellationToken cancellationToken)
+ {
+ if (!Input.HasValue)
+ {
+ Console.Error.WriteLine(CertificateDecoder.InvalidInputOrFileCommand);
+ return -1;
+ }
+
+ ResultInfo<string> result
+ = await Input.Value.Match(
+ async inputFile =>
+ {
+ if (!_fileStorage.FileExists(inputFile.FullName))
+ {
+ return new ResultInfo<string>("", false);
+ }
+
+ using Stream fileStream = _fileStorage.OpenReadFile(inputFile.FullName);
+ using var memStream = new MemoryStream();
+ await fileStream.CopyToAsync(memStream, cancellationToken);
+ byte[] bytes = memStream.ToArray();
+
+ string rawCertificateString = CertificateHelper.GetRawCertificateString(bytes);
+
+ return new ResultInfo<string>(rawCertificateString, true);
+ },
+ inputString => Task.FromResult(new ResultInfo<string>(inputString, true)));
+
+ if (!result.HasSucceeded)
+ {
+ Console.Error.WriteLine(CertificateDecoder.InputFileNotFound);
+ return -1;
+ }
+
+ Guard.IsNotNull(result.Data);
+
+ string? decoded = null;
+ bool success = false;
+ if (!string.IsNullOrWhiteSpace(result.Data))
+ {
+ success = CertificateHelper.TryDecodeCertificate(
+ logger,
+ result.Data,
+ Password,
+ out decoded);
+ }
+
+ cancellationToken.ThrowIfCancellationRequested();
+
+ if (success)
+ {
+ await FileHelper.WriteOutputAsync(decoded ?? string.Empty, OutputFile, cancellationToken);
+ return 0;
+ }
+ else
+ {
+ Console.Error.WriteLine(decoded);
+ return -1;
+ }
+ }
+}
diff --git a/src/app/dev/DevToys.Tools/Tools/EncodersDecoders/Certificate/CertificateDecoderGuiTool.cs b/src/app/dev/DevToys.Tools/Tools/EncodersDecoders/Certificate/CertificateDecoderGuiTool.cs
new file mode 100644
index 000000000..3e1691e41
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/Tools/EncodersDecoders/Certificate/CertificateDecoderGuiTool.cs
@@ -0,0 +1,163 @@
+using DevToys.Tools.Helpers;
+using DevToys.Tools.SmartDetection;
+
+namespace DevToys.Tools.Tools.EncodersDecoders.Certificate;
+
+[Export(typeof(IGuiTool))]
+[Name("CertificateDecoder")]
+[ToolDisplayInformation(
+ IconFontName = "DevToys-Tools-Icons",
+ IconGlyph = '\u0135',
+ GroupName = PredefinedCommonToolGroupNames.EncodersDecoders,
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),
+ ResourceManagerBaseName = "DevToys.Tools.Tools.EncodersDecoders.Certificate.CertificateDecoder",
+ ShortDisplayTitleResourceName = nameof(CertificateDecoder.ShortDisplayTitle),
+ LongDisplayTitleResourceName = nameof(CertificateDecoder.LongDisplayTitle),
+ DescriptionResourceName = nameof(CertificateDecoder.Description),
+ AccessibleNameResourceName = nameof(CertificateDecoder.AccessibleName),
+ SearchKeywordsResourceName = nameof(CertificateDecoder.SearchKeywords))]
+[AcceptedDataTypeName(CertificateDetector.InternalName)]
+internal sealed class CertificateDecoderGuiTool : IGuiTool, IDisposable
+{
+ private enum GridRows
+ {
+ TopAuto,
+ Stretch,
+ }
+
+ private enum GridColumns
+ {
+ Stretch
+ }
+
+ private readonly DisposableSemaphore _semaphore = new();
+ private readonly IUIPasswordInput _password = PasswordInput("certificate-decoder-password-input");
+ private readonly IUIFileSelector _fileSelector = FileSelector("certificate-decoder-file-selector");
+ private readonly IUIMultiLineTextInput _inputText = MultilineTextInput("certificate-decoder-input");
+ private readonly IUIMultiLineTextInput _outputText = MultilineTextInput("certificate-decoder-output");
+
+ private CancellationTokenSource? _cancellationTokenSource;
+
+ // For unit tests.
+ internal Task? WorkTask { get; private set; }
+
+ public UIToolView View
+ => new(
+ isScrollable: false,
+ SplitGrid()
+ .Vertical()
+ .LeftPaneLength(new UIGridLength(1, UIGridUnitType.Fraction))
+ .RightPaneLength(new UIGridLength(1, UIGridUnitType.Fraction))
+
+ .WithLeftPaneChild(
+ Grid()
+ .ColumnSmallSpacing()
+
+ .Rows(
+ (GridRows.TopAuto, Auto),
+ (GridRows.Stretch, new UIGridLength(1, UIGridUnitType.Fraction)))
+
+ .Columns(
+ (GridColumns.Stretch, new UIGridLength(1, UIGridUnitType.Fraction)))
+
+ .Cells(
+ Cell(
+ GridRows.TopAuto,
+ GridColumns.Stretch,
+
+ Stack()
+ .Vertical()
+ .LargeSpacing()
+ .WithChildren(
+
+ _password
+ .Title(CertificateDecoder.PasswordTitle)
+ .OnTextChanged(OnPasswordChanged),
+
+ _fileSelector
+ .CanSelectOneFile()
+ .LimitFileTypesTo("pem", "crt", "pfx", "cer")
+ .OnFilesSelected(OnFileSelectedAsync))),
+
+ Cell(
+ GridRows.Stretch,
+ GridColumns.Stretch,
+
+ _inputText
+ .Title(CertificateDecoder.InputTitle)
+ .CanCopyWhenEditable()
+ .AlwaysWrap()
+ .OnTextChanged(OnInputTextChanged))))
+
+ .WithRightPaneChild(
+ _outputText
+ .ReadOnly()
+ .Extendable()
+ .Title(CertificateDecoder.OutputTitle)));
+
+ public void OnDataReceived(string dataTypeName, object? parsedData)
+ {
+ if (dataTypeName == CertificateDetector.InternalName && parsedData is string text)
+ {
+ _inputText.Text(text); // This will trigger a decoding task.
+ }
+ }
+
+ public void Dispose()
+ {
+ _cancellationTokenSource?.Cancel();
+ _cancellationTokenSource?.Dispose();
+ _semaphore.Dispose();
+ }
+
+ private async ValueTask OnFileSelectedAsync(SandboxedFileReader[] files)
+ {
+ Guard.HasSizeEqualTo(files, 1);
+
+ using SandboxedFileReader selectedFile = files[0];
+ using var memStream = new MemoryStream();
+
+ await selectedFile.CopyFileContentToAsync(memStream, CancellationToken.None);
+
+ byte[] bytes = memStream.ToArray();
+ string rawCertificateString = CertificateHelper.GetRawCertificateString(bytes);
+
+ _inputText.Text(rawCertificateString); // This will trigger a decoding task.
+ }
+
+ private void OnInputTextChanged(string text)
+ {
+ StartDecoding();
+ }
+
+ private void OnPasswordChanged(string text)
+ {
+ StartDecoding();
+ }
+
+ private void StartDecoding()
+ {
+ _cancellationTokenSource?.Cancel();
+ _cancellationTokenSource?.Dispose();
+ _cancellationTokenSource = new CancellationTokenSource();
+
+ WorkTask = DecodeAsync(_inputText.Text, _password.Text, _cancellationTokenSource.Token);
+ }
+
+ private async Task DecodeAsync(string rawCertificateString, string password, CancellationToken cancellationToken)
+ {
+ await TaskSchedulerAwaiter.SwitchOffMainThreadAsync(cancellationToken);
+
+ string? decoded = null;
+ if (!string.IsNullOrWhiteSpace(rawCertificateString))
+ {
+ CertificateHelper.TryDecodeCertificate(
+ this.Log(),
+ rawCertificateString,
+ password,
+ out decoded);
+ }
+
+ _outputText.Text(decoded ?? string.Empty);
+ }
+}
diff --git a/src/app/tests/DevToys.UnitTests/DevToys.UnitTests.csproj b/src/app/tests/DevToys.UnitTests/DevToys.UnitTests.csproj
index c357e6bbf..35799cf4b 100644
--- a/src/app/tests/DevToys.UnitTests/DevToys.UnitTests.csproj
+++ b/src/app/tests/DevToys.UnitTests/DevToys.UnitTests.csproj
@@ -12,6 +12,36 @@
<Content Include="Tools\TestData\Base64ImageEncoderDecoder\Png_transparency_demonstration_1_base64.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
+ <Content Include="Tools\TestData\CertificateDecoder\CertDecoded.txt">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="Tools\TestData\CertificateDecoder\CertificateRequest.txt">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="Tools\TestData\CertificateDecoder\CertWithExtensionsDecoded.txt">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="Tools\TestData\CertificateDecoder\PemCertPublic.txt">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="Tools\TestData\CertificateDecoder\PemCertPublicWithExtensions.txt">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="Tools\TestData\CertificateDecoder\PemCertWithPrivateKey.txt">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="Tools\TestData\CertificateDecoder\PemCertWithPrivateKeyWithExtensions.txt">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="Tools\TestData\CertificateDecoder\PfxNoPassword.pfx">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="Tools\TestData\CertificateDecoder\PfxWithExtensionsNoPassword.pfx">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="Tools\TestData\CertificateDecoder\PfxWithPassword.pfx">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
<Content Include="Tools\TestData\HashAndChecksumGenerator\Checksum.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
diff --git a/src/app/tests/DevToys.UnitTests/Tools/EncodersDecoders/Certificate/CertificateDecoderCommandLineToolTests.cs b/src/app/tests/DevToys.UnitTests/Tools/EncodersDecoders/Certificate/CertificateDecoderCommandLineToolTests.cs
new file mode 100644
index 000000000..4268905b2
--- /dev/null
+++ b/src/app/tests/DevToys.UnitTests/Tools/EncodersDecoders/Certificate/CertificateDecoderCommandLineToolTests.cs
@@ -0,0 +1,82 @@
+using System.IO;
+using System.Threading;
+using System.Threading.Tasks;
+using DevToys.CLI;
+using DevToys.Tools.Tools.EncodersDecoders.Certificate;
+using DevToys.UnitTests.Tools.Helpers;
+
+namespace DevToys.UnitTests.Tools.EncodersDecoders.Certificate;
+
+[Collection(nameof(TestParallelizationDisabled))]
+public sealed class CertificateDecoderCommandLineToolTests : MefBasedTest
+{
+ private readonly CertificateDecoderCommandLineTool _tool;
+ private readonly string _baseTestDataDirectory = Path.Combine("Tools", "TestData", nameof(CertificateDecoder));
+
+ public CertificateDecoderCommandLineToolTests()
+ : base(typeof(CertificateDecoderCommandLineTool).Assembly)
+ {
+ _tool = (CertificateDecoderCommandLineTool)MefProvider.ImportMany<ICommandLineTool, CommandLineToolMetadata>()
+ .Single(t => t.Metadata.InternalComponentName == "CertificateDecoder")
+ .Value;
+ }
+
+ [Fact]
+ public async Task ReadCertificateFromFile()
+ {
+ string filePath = Path.Combine(_baseTestDataDirectory, "PfxWithPassword.pfx");
+ FileInfo inputFile = TestDataProvider.GetFile(filePath);
+
+ _tool.Input = inputFile;
+
+ using (var consoleOutput = new ConsoleOutputMonitor())
+ {
+ await _tool.InvokeAsync(new MockILogger(), CancellationToken.None);
+
+ string result = consoleOutput.GetError().Trim();
+ result.Should().Be(CertificateDecoder.InvalidPasswordError);
+ }
+
+ _tool.Password = "test1234";
+
+ using (var consoleOutput = new ConsoleOutputMonitor())
+ {
+ await _tool.InvokeAsync(new MockILogger(), CancellationToken.None);
+
+ string expectedResult = CertificateHelperTests.CleanDateTimes(File.ReadAllText(TestDataProvider.GetFile(Path.Combine(_baseTestDataDirectory, "CertDecoded.txt")).FullName)).Trim();
+ string result = CertificateHelperTests.CleanDateTimes(consoleOutput.GetOutput()).Trim();
+ result.Should().Be(expectedResult);
+ }
+ }
+
+ [Fact]
+ public async Task ReadCertificateFromText()
+ {
+ string input = File.ReadAllText(TestDataProvider.GetFile(Path.Combine(_baseTestDataDirectory, "PemCertPublic.txt")).FullName);
+
+ _tool.Input = input;
+
+ using (var consoleOutput = new ConsoleOutputMonitor())
+ {
+ await _tool.InvokeAsync(new MockILogger(), CancellationToken.None);
+
+ string expectedResult = CertificateHelperTests.CleanDateTimes(File.ReadAllText(TestDataProvider.GetFile(Path.Combine(_baseTestDataDirectory, "CertDecoded.txt")).FullName)).Trim();
+ string result = CertificateHelperTests.CleanDateTimes(consoleOutput.GetOutput()).Trim();
+ result.Should().Be(expectedResult);
+ }
+ }
+
+ [Fact]
+ public async Task InvalidCertificate()
+ {
+ _tool.Input = "hello";
+
+ using (var consoleOutput = new ConsoleOutputMonitor())
+ {
+ await _tool.InvokeAsync(new MockILogger(), CancellationToken.None);
+
+ string result = consoleOutput.GetError().Trim();
+ result.Should().Be(CertificateDecoder.UnsupportedFormatError);
+ }
+ }
+}
diff --git a/src/app/tests/DevToys.UnitTests/Tools/EncodersDecoders/Certificate/CertificateDecoderGuiToolTests.cs b/src/app/tests/DevToys.UnitTests/Tools/EncodersDecoders/Certificate/CertificateDecoderGuiToolTests.cs
new file mode 100644
index 000000000..0751e5374
--- /dev/null
+++ b/src/app/tests/DevToys.UnitTests/Tools/EncodersDecoders/Certificate/CertificateDecoderGuiToolTests.cs
@@ -0,0 +1,78 @@
+using System.IO;
+using System.Threading.Tasks;
+using DevToys.Blazor.Core;
+using DevToys.Core.Tools.Metadata;
+using DevToys.Tools.Tools.EncodersDecoders.Certificate;
+using DevToys.UnitTests.Tools.Helpers;
+
+namespace DevToys.UnitTests.Tools.EncodersDecoders.Certificate;
+
+public sealed class CertificateDecoderGuiToolTests : MefBasedTest
+{
+ private readonly CertificateDecoderGuiTool _tool;
+ private readonly UIToolView _toolView;
+ private readonly IUIMultiLineTextInput _inputBox;
+ private readonly IUISingleLineTextInput _password;
+ private readonly IUIMultiLineTextInput _outputBox;
+ private readonly IUIFileSelector _fileSelector;
+ private readonly string _baseTestDataDirectory = Path.Combine("Tools", "TestData", nameof(CertificateDecoder));
+
+ public CertificateDecoderGuiToolTests()
+ : base(typeof(CertificateDecoderGuiTool).Assembly)
+ {
+ _tool = (CertificateDecoderGuiTool)MefProvider.ImportMany<IGuiTool, GuiToolMetadata>()
+ .Single(t => t.Metadata.InternalComponentName == "CertificateDecoder")
+ .Value;
+
+ _toolView = _tool.View;
+
+ _inputBox = (IUIMultiLineTextInput)_toolView.GetChildElementById("certificate-decoder-input");
+ _outputBox = (IUIMultiLineTextInput)_toolView.GetChildElementById("certificate-decoder-output");
+ _password = (IUIPasswordInput)_toolView.GetChildElementById("certificate-decoder-password-input");
+ _fileSelector = (IUIFileSelector)_toolView.GetChildElementById("certificate-decoder-file-selector");
+ }
+
+ [Fact]
+ public async Task ReadCertificateFromFile()
+ {
+ string filePath = Path.Combine(_baseTestDataDirectory, "PfxWithPassword.pfx");
+ FileInfo inputFile = TestDataProvider.GetFile(filePath);
+ using var fileStream = new BlazorSandboxedFileReader(inputFile, new MockIFileStorage());
+
+ _fileSelector.WithFiles(fileStream);
+
+ await Task.Delay(300); // Delay because the IUIFileSelector.SelectedFiles setter is async but we don't wait for it to finish. Could be improved in the future.
+ await _tool.WorkTask;
+
+ _outputBox.Text.Should().Be(CertificateDecoder.InvalidPasswordError);
+
+ _password.Text("test1234");
+ await _tool.WorkTask;
+
+ string expectResult = CertificateHelperTests.CleanDateTimes(File.ReadAllText(TestDataProvider.GetFile(Path.Combine(_baseTestDataDirectory, "CertDecoded.txt")).FullName));
+ CertificateHelperTests.CleanDateTimes(_outputBox.Text).Should().Be(expectResult);
+ }
+
+ [Fact]
+ public async Task ReadCertificateFromText()
+ {
+ string input = File.ReadAllText(TestDataProvider.GetFile(Path.Combine(_baseTestDataDirectory, "PemCertPublic.txt")).FullName);
+
+ _inputBox.Text(input);
+
+ await _tool.WorkTask;
+
+ string expectResult = CertificateHelperTests.CleanDateTimes(File.ReadAllText(TestDataProvider.GetFile(Path.Combine(_baseTestDataDirectory, "CertDecoded.txt")).FullName));
+ CertificateHelperTests.CleanDateTimes(_outputBox.Text).Should().Be(expectResult);
+ }
+
+ [Fact]
+ public async Task InvalidCertificate()
+ {
+ _inputBox.Text("hello");
+
+ await _tool.WorkTask;
+
+ _outputBox.Text.Should().Be(CertificateDecoder.UnsupportedFormatError);
+ }
+}
diff --git a/src/app/tests/DevToys.UnitTests/Tools/Helpers/CertificateHelperTests.cs b/src/app/tests/DevToys.UnitTests/Tools/Helpers/CertificateHelperTests.cs
new file mode 100644
index 000000000..1b9a193e1
--- /dev/null
+++ b/src/app/tests/DevToys.UnitTests/Tools/Helpers/CertificateHelperTests.cs
@@ -0,0 +1,85 @@
+using System.IO;
+using System.Text;
+using DevToys.Tools.Helpers;
+using DevToys.Tools.Tools.EncodersDecoders.Certificate;
+
+namespace DevToys.UnitTests.Tools.Helpers;
+
+public class CertificateHelperTests
+{
+ private static readonly string baseTestDataDirectory = Path.Combine("Tools", "TestData", nameof(CertificateDecoder));
+
+ [Theory]
+ [InlineData("PemCertPublic.txt", null, true, "CertDecoded.txt")]
+ [InlineData("PemCertWithPrivateKey.txt", null, true, "CertDecoded.txt")]
+ [InlineData("PfxNoPassword.pfx", null, true, "CertDecoded.txt")]
+ [InlineData("PfxWithPassword.pfx", "test1234", true, "CertDecoded.txt")]
+ [InlineData("PemCertPublicWithExtensions.txt", null, true, "CertWithExtensionsDecoded.txt")]
+ [InlineData("PemCertWithPrivateKeyWithExtensions.txt", null, true, "CertWithExtensionsDecoded.txt")]
+ [InlineData("PfxWithExtensionsNoPassword.pfx", null, true, "CertWithExtensionsDecoded.txt")]
+ public void DecodeCertificateSuccess(string input, string password, bool successfullyDecoded, string expectedResult)
+ => DecodeCertificate(input, password, successfullyDecoded, expectedResult);
+
+ [Fact]
+ public void DecodeCertificateErrors()
+ {
+ // Cannot populate these vars via DataRow because https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0182?f1url=%3FappId%3Droslyn%26k%3Dk(CS0182)
+ DecodeCertificate("PfxWithPassword.pfx", "wrong password!", false, CertificateDecoder.InvalidPasswordError);
+ DecodeCertificate("CertificateRequest.txt", null, false, CertificateDecoder.UnsupportedFormatError);
+ }
+
+ private static void DecodeCertificate(string inputFile, string password, bool successfullyDecoded, string expectedResultFile)
+ {
+ string inputFilePath = TestDataProvider.GetFile(Path.Combine(baseTestDataDirectory, inputFile)).FullName;
+
+ string input;
+ if (inputFilePath.EndsWith(".pfx", StringComparison.OrdinalIgnoreCase))
+ {
+ byte[] data = File.ReadAllBytes(inputFilePath);
+ input = CertificateHelper.GetRawCertificateString(data);
+ }
+ else
+ {
+ input = File.ReadAllText(inputFilePath);
+ }
+
+ string expectedResult;
+ string expectedResultFilePath = TestDataProvider.GetFile(Path.Combine(baseTestDataDirectory, expectedResultFile)).FullName;
+ if (File.Exists(expectedResultFilePath))
+ {
+ expectedResult = File.ReadAllText(TestDataProvider.GetFile(Path.Combine(baseTestDataDirectory, expectedResultFile)).FullName);
+ }
+ else
+ {
+ expectedResult = expectedResultFile;
+ }
+
+ bool result = CertificateHelper.TryDecodeCertificate(new MockILogger(), input, password, out string decoded);
+ decoded = CleanDateTimes(decoded);
+ expectedResult = CleanDateTimes(expectedResult);
+
+ result.Should().Be(successfullyDecoded);
+ expectedResult.Should().Be(decoded);
+ }
+
+ /// <summary>
+ /// Strips times from decoded certificates to avoid issues with testing in different timezones
+ /// </summary>
+ internal static string CleanDateTimes(string decoded)
+ {
+ var decodedCleaned = new StringBuilder();
+ foreach (string line in decoded.Split(Environment.NewLine))
+ {
+ if (DateTime.TryParse(line, out DateTime dateTime))
+ {
+ decodedCleaned.AppendLine($" {dateTime.Date}");
+ }
+ else
+ {
+ decodedCleaned.AppendLine(line);
+ }
+ }
+
+ return decodedCleaned.ToString();
+ }
+}
diff --git a/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/CertDecoded.txt b/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/CertDecoded.txt
new file mode 100644
index 000000000..bffd9b1dd
--- /dev/null
+++ b/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/CertDecoded.txt
@@ -0,0 +1,17 @@
+[Subject]
+ O=Dev Toys, S=Some-State, C=DT
+
+[Issuer]
+ O=Dev Toys, S=Some-State, C=DT
+
+[Serial Number]
+ 27C9D3678BC89528786CEC0642454A3971E4FF23
+
+[Not Before]
+ 4/17/2023 2:40:48 PM
+
+[Not After]
+ 4/16/2024 2:40:48 PM
+
+[Thumbprint]
+ 9E5B55F43B571EFE82D386C856506FC96018217C
diff --git a/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/CertWithExtensionsDecoded.txt b/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/CertWithExtensionsDecoded.txt
new file mode 100644
index 000000000..8d5362bd8
--- /dev/null
+++ b/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/CertWithExtensionsDecoded.txt
@@ -0,0 +1,27 @@
+[Subject]
+ O=Dev-Toys, S=Some-State, C=DT
+
+[Issuer]
+ O=Dev-Toys, S=Some-State, C=DT
+
+[Serial Number]
+ 0A2D679783C5DB71139A0EEB3479D4F7D5C76E79
+
+[Not Before]
+ 6/2/2023 9:12:03 AM
+
+[Not After]
+ 5/30/2033 9:12:03 AM
+
+[Thumbprint]
+ 41D8D90FE633CFF63CED9E4A53889C0133AEF106
+
+[Subject Key Identifier]
+ 269dfeada0872cc64350792c2558df6fa086c41b
+
+[Authority Key Identifier]
+ KeyID=269dfeada0872cc64350792c2558df6fa086c41b
+
+[Basic Constraints]
+ Subject Type=CA
+ Path Length Constraint=None
\ No newline at end of file
diff --git a/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/CertificateRequest.txt b/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/CertificateRequest.txt
new file mode 100644
index 000000000..673369901
--- /dev/null
+++ b/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/CertificateRequest.txt
@@ -0,0 +1,26 @@
+-----BEGIN CERTIFICATE REQUEST-----
+MIIEejCCAmICAQAwNTELMAkGA1UEBhMCRFQxEzARBgNVBAgMClNvbWUtU3RhdGUx
+ETAPBgNVBAoMCERldiBUb3lzMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKC
+AgEA25PEtgiFZvzv/MR0UhrRGGdl3opOr7rrK+lPzak3pERnfVtN/vF8054CtI5a
+1rzQB80IpULDZSMKLZB7R76k1lTpOOUXkspWeVbRchP0GJHHEndMsAmkGIt4f87S
++KRbHhK+V63sOtPdJbtLUIrHIBAX4Ma8SQfx3OobIrOPVh63oU7NjX0Os0ByD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YCU8wIfQxCMeZTdQOs1rX6CnXrSknz3jJqkytjn4b1ltWOtFzqs64
+g41z4JMbh1zbm2xp2VoHTW9XAfr64/J5kJpf6EQcDkmEhb9Wz5PphjMgIEHfYCWb
+dX+wpfqTJYWcw64txwyskqsxizFsZ4zTMObcHy6Q/puVlO9LtO4FW59Kd7YrAw==
+-----END CERTIFICATE REQUEST-----
\ No newline at end of file
diff --git a/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/PemCertPublic.txt b/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/PemCertPublic.txt
new file mode 100644
index 000000000..eca6d3c2d
--- /dev/null
+++ b/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/PemCertPublic.txt
@@ -0,0 +1,29 @@
+-----BEGIN CERTIFICATE-----
+MIIE8TCCAtkCFCfJ02eLyJUoeGzsBkJFSjlx5P8jMA0GCSqGSIb3DQEBCwUAMDUx
+CzAJBgNVBAYTAkRUMRMwEQYDVQQIDApTb21lLVN0YXRlMREwDwYDVQQKDAhEZXYg
+VG95czAeFw0yMzA0MTcxNDQwNDhaFw0yNDA0MTYxNDQwNDhaMDUxCzAJBgNVBAYT
+AkRUMRMwEQYDVQQIDApTb21lLVN0YXRlMREwDwYDVQQKDAhEZXYgVG95czCCAiIw
+DQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBANuTxLYIhWb87/zEdFIa0RhnZd6K
+Tq+66yvpT82pN6REZ31bTf7xfNOeArSOWta80AfNCKVCw2UjCi2Qe0e+pNZU6Tjl
+F5LKVnlW0XIT9BiRxxJ3TLAJpBiLeH/O0vikWx4Svlet7DrT3SW7S1CKxyAQF+DG
+vEkH8dzqGyKzj1Yet6FOzY19DrNAcg+3yjm36bRYe24ykJ5wJ7g6v4TTwg4sW8bG
+QDhvDmCMSlj4II7UCFj2w7uK0z1XBHvzsp0cBikQiUpTOvR3MZA4uzFevIPq/GWg
+o4Hljp6qhVmYNC3dcjyLQjWyLYMIV3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rxZVdW1KtaT
+ixUiDYhfU7a41ebpMlwMfA+QAuK0
+-----END CERTIFICATE-----
\ No newline at end of file
diff --git a/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/PemCertPublicWithExtensions.txt b/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/PemCertPublicWithExtensions.txt
new file mode 100644
index 000000000..f119c24df
--- /dev/null
+++ b/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/PemCertPublicWithExtensions.txt
@@ -0,0 +1,31 @@
+-----BEGIN CERTIFICATE-----
+MIIFSzCCAzOgAwIBAgIUCi1nl4PF23ETmg7rNHnU99XHbnkwDQYJKoZIhvcNAQEL
+BQAwNTELMAkGA1UEBhMCRFQxEzARBgNVBAgMClNvbWUtU3RhdGUxETAPBgNVBAoM
+CERldi1Ub3lzMB4XDTIzMDYwMjEzMTIwM1oXDTMzMDUzMDEzMTIwM1owNTELMAkG
+A1UEBhMCRFQxEzARBgNVBAgMClNvbWUtU3RhdGUxETAPBgNVBAoMCERldi1Ub3lz
+MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAuxTovybg74QlGSo7lGlX
+Kxz7nq0Mfvulj+t2NVfGXEu6VUTaDZNDYwynRR397N82RKsYt17dSkjUYWZI5nsu
+QfH9LJIlstokqu+6/CXA5T79TGNYVz9iFbMQXNy+M2zLaO42LCOHUs8oYFB5FXL7
+x6nXmtsJUB0eITPc2wrKCN7SY3QuMZ/A6Bn2dVJ+7+2SwCRLv7SDDGX/jxiLCxXn
+tdmgv/PKQnxq0JXIi3n1BOrdz6e9DYDMjPR5FkZWh0TEjFMpCSxqq/IfQc/DNYii
+ragXuvoVpLHswRu4C8ytksZYEg+RjozqjTpVI4c++xXQpNK4zIs0bI6bkczj4T97
+WEzE3xE90RD7gG09tEL7/dKeok5o0zC6N+1rNTPMKTwDPEUig8uNcplN7W5vWehi
+ixJGceIFb91zMr+W1ImY39cFllQZnQrBvfsoq0IxHaad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klO7Ij+xNx
+ulEjWxGlNtL7tLMeToVU
+-----END CERTIFICATE-----
\ No newline at end of file
diff --git a/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/PemCertWithPrivateKey.txt b/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/PemCertWithPrivateKey.txt
new file mode 100644
index 000000000..5e5817b67
--- /dev/null
+++ b/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/PemCertWithPrivateKey.txt
@@ -0,0 +1,82 @@
+-----BEGIN PRIVATE KEY-----
+MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQDbk8S2CIVm/O/8
+xHRSGtEYZ2Xeik6vuusr6U/NqTekRGd9W03+8XzTngK0jlrWvNAHzQilQsNlIwot
+kHtHvqTWVOk45ReSylZ5VtFyE/QYkccSd0ywCaQYi3h/ztL4pFseEr5Xrew6090l
+u0tQiscgEBfgxrxJB/Hc6hsis49WHrehTs2NfQ6zQHIPt8o5t+m0WHtuMpCecCe4
+Or+E08IOLFvGxkA4bw5gjEpY+CCO1AhY9sO7itM9VwR787KdHAYpEIlKUzr0dzGQ
+OLsxXryD6vxloKOB5Y6eqoVZmDQt3XI8i0I1si2DCFd1raqti/lWwOnuP8A8OXQg
+dNO0QAEKdnXCx/+cm1WeMGTzPGbMedkrXOM8oAys62WaKeAYToqdVAtWvRwMd/Tq
+5RdwdlYtNVWjTM7cL4WxuLWWoWVSk23JJFfZgLce3PsUwJY8dLms+nyM754c4qga
+JMUEEy5sigB1z3T2qJjGv0Oa7mqQT38CMPcYDgs8ow1J9dX1DvltO+BeFe2HzfGk
+XaMXWrFOHP0txXryWaj7F4EAHnBE3sFxXW19gxU7PCEf2M+lB3mWjI45eYOpVQC3
+vzRb5qqebC5vU2TO4WkBt4T/aLPxJemFyCvWMoIX/+RXV98W6PD6WNarqFbjNG4B
+0DrOjOSRkZtNlQt8zVdFg0h21bBodQIDAQABAoICAE264cgO/CqZH9u7L/J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evToys.UnitTests/Tools/TestData/CertificateDecoder/PemCertWithPrivateKeyWithExtensions.txt b/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/PemCertWithPrivateKeyWithExtensions.txt
new file mode 100644
index 000000000..dc4375ece
--- /dev/null
+++ b/src/app/tests/DevToys.UnitTests/Tools/TestData/CertificateDecoder/PemCertWithPrivateKeyWithExtensions.txt
@@ -0,0 +1,84 @@
+-----BEGIN PRIVATE KEY-----
+MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQC7FOi/JuDvhCUZ
+KjuUaVcrHPuerQx++6WP63Y1V8ZcS7pVRNoNk0NjDKdFHf3s3zZEqxi3Xt1KSNRh
+Zkjmey5B8f0skiWy2iSq77r8JcDlPv1MY1hXP2IVsxBc3L4zbMto7jYsI4dSzyhg
+UHkVcvvHqdea2wlQHR4hM9zbCsoI3tJjdC4xn8DoGfZ1Un7v7ZLAJEu/tIMMZf+P
+GIsLFee12aC/88pCfGrQlciLefUE6t3Pp70NgMyM9HkWRlaHRMSMUykJLGqr8h9B
+z8M1iKKtqBe6+hWksezBG7gLzK2SxlgSD5GOjOqNOlUjhz77FdCk0rjMizRsjpuR
+zOPhP3tYTMTfET3REPuAbT20Qvv90p6iTmjTMLo37Ws1M8wpPAM8RSKDy41ymU3t
+bm9Z6GKLEkZx4gVv3XMyv5bUiZjf1wWWVBmdCsG9+yirQjEdpp1iN28D8LYfUWwU
+9PhKBIcP/0eBbK7XAC3t7/Fwdr04zvVpzVKlc3ZuvRSnQ/hJNc96iV/kjQGwB981
+1GspEzRxJml+2cz+AWOglVx3a6dUDiy4WhcCscZJEp2o9vdeOepwVTsyMcPJxFfO
+F9SP3RpOH2mDqWi9jWCr1NLy980LrN39bYZzEMPb442OwYGd+YXgEuj15V4y7eS+
+0wb2XT0llkqpBzTH0jHBNnHUk/YJVQIDAQABAoICABqFpVVsIplyJ3xA039/y57O
+FhHxwILEFD2qCPEZB4MQLVNnVm50QSpqodAXp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