Skip to content

Commit e4428f7

Browse files
committed
Yet another method
1 parent c1c922d commit e4428f7

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

src/Quickwarden.Infrastructure/WindowsHelloSecretRepository.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#if WINDOWS
22
using System.Runtime.InteropServices.WindowsRuntime;
33
using System.Security.Cryptography;
4-
using System.Security.Cryptography.Pkcs;
54
using System.Security.Cryptography.X509Certificates;
65
using System.Security.Principal;
76
using System.Text;
@@ -54,25 +53,22 @@ private static string ToApplicationSecret(KeyCredential credential)
5453

5554
private static async Task<string> GetCertificateKey()
5655
{
57-
SignedCms signedCms = new SignedCms();
5856
if (string.IsNullOrWhiteSpace(Environment.ProcessPath))
5957
return string.Empty;
60-
61-
var assembly = await File.ReadAllBytesAsync(Environment.ProcessPath);
6258
try
6359
{
64-
signedCms.Decode(assembly);
60+
var executingCert = X509Certificate.CreateFromSignedFile(Environment.ProcessPath);
61+
if (executingCert == null)
62+
return string.Empty;
63+
var assemblyKey = executingCert.GetPublicKey();
64+
var keyHash = SHA256.HashData(assemblyKey);
65+
66+
return Convert.ToBase64String(keyHash);
6567
}
66-
catch (Exception)
68+
catch (CryptographicException)
6769
{
6870
return string.Empty;
6971
}
70-
var certificate = signedCms.Certificates[0];
71-
var publicKey = certificate?.GetRSAPublicKey();
72-
var publicKeyBytes = Encoding.UTF8.GetBytes(publicKey?.ToXmlString(false) ?? string.Empty);
73-
var keyHash = SHA256.HashData(publicKeyBytes);
74-
75-
return Convert.ToBase64String(keyHash);
7672
}
7773
}
7874
#else

0 commit comments

Comments
 (0)