File tree Expand file tree Collapse file tree
src/Quickwarden.Infrastructure Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#if WINDOWS
22using System . Runtime . InteropServices . WindowsRuntime ;
33using System . Security . Cryptography ;
4- using System . Security . Cryptography . Pkcs ;
54using System . Security . Cryptography . X509Certificates ;
65using System . Security . Principal ;
76using 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
You can’t perform that action at this time.
0 commit comments