-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Keegan Caruso
committed
Aug 14, 2024
1 parent
e8605c2
commit c920979
Showing
3 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ jobs: | |
- name: Setup .NET 9.0.x | ||
uses: actions/[email protected] | ||
with: | ||
dotnet-version: 9.0.100-preview.4.24267.66 | ||
dotnet-version: 9.0.100-preview.7.24407.12 | ||
|
||
- name: Run the tests | ||
run: dotnet test Wilson.sln | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Security; | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
namespace Microsoft.IdentityModel.TestUtils | ||
{ | ||
public static class X509Helper | ||
{ | ||
public static X509Certificate2 ConvertToX509Certificate(string base64Data) | ||
{ | ||
var base64Bytes = Convert.FromBase64String(base64Data); | ||
|
||
#if NET9_0_OR_GREATER | ||
return X509CertificateLoader.LoadCertificate(base64Bytes); | ||
#else | ||
return new X509Certificate2(base64Bytes); | ||
#endif | ||
} | ||
|
||
public static X509Certificate2 ConvertToX509Certificate(string base64Data, SecureString securePassword, X509KeyStorageFlags flags = X509KeyStorageFlags.DefaultKeySet) | ||
{ | ||
var password = ConvertFromSecureString(securePassword); | ||
return ConvertToX509Certificate(base64Data, password, flags); | ||
} | ||
|
||
public static X509Certificate2 ConvertToX509Certificate(string base64Data, string password, X509KeyStorageFlags flags = X509KeyStorageFlags.DefaultKeySet) | ||
{ | ||
var base64Bytes = Convert.FromBase64String(base64Data); | ||
#if NET9_0_OR_GREATER | ||
return X509CertificateLoader.LoadPkcs12(base64Bytes, password, flags); | ||
#else | ||
return new X509Certificate2(base64Bytes, password); | ||
#endif | ||
} | ||
|
||
private static string ConvertFromSecureString(SecureString secureString) | ||
{ | ||
IntPtr valuePtr = IntPtr.Zero; | ||
try | ||
{ | ||
valuePtr = Marshal.SecureStringToGlobalAllocUnicode(secureString); | ||
return Marshal.PtrToStringUni(valuePtr); | ||
} | ||
finally | ||
{ | ||
Marshal.ZeroFreeGlobalAllocUnicode(valuePtr); | ||
} | ||
} | ||
} | ||
} |