Exemplo n.º 1
0
        private static SpkiHashesModel CalculateHashes(X509Certificate2 certificate, bool reportOnly, PublicPinnedKeys pinnedKeys)
        {
            var sha256 = CertificateHashBuilder.BuildHashForPublicKey <SHA256CryptoServiceProvider>(certificate);
            var sha1   = CertificateHashBuilder.BuildHashForPublicKey <SHA1CryptoServiceProvider>(certificate);
            var model  = new SpkiHashesModel
            {
                Hashes = new ObservableCollection <SpkiHashModel>
                {
                    new SpkiHashModel
                    {
                        ReportOnly = reportOnly,
                        Algorithm  = PinAlgorithm.SHA1,
                        HashBase64 = sha1,
                        IsPinned   = pinnedKeys?.PinnedKeys?.Any(pk => pk.FingerprintBase64 == sha1) ?? false
                    },
                    new SpkiHashModel
                    {
                        ReportOnly = reportOnly,
                        Algorithm  = PinAlgorithm.SHA256,
                        HashBase64 = sha256,
                        IsPinned   = pinnedKeys?.PinnedKeys?.Any(pk => pk.FingerprintBase64 == sha256) ?? false
                    },
                }
            };

            return(model);
        }
Exemplo n.º 2
0
 private static SpkiHashesModel CalculateHashes(X509Certificate2 certificate, bool reportOnly, PublicPinnedKeys pinnedKeys)
 {
     var sha256 = CertificateHashBuilder.BuildHashForPublicKeyBinary<SHA256CryptoServiceProvider>(certificate);
     var model = new SpkiHashesModel
     {
         Hashes = new ObservableCollection<SpkiHashModel>
         {
             new SpkiHashModel
             {
                 ReportOnly = reportOnly,
                 Algorithm = PinAlgorithm.SHA256,
                 Hash = sha256,
                 IsPinned = pinnedKeys?.PinnedKeys?.Any(pk => pk.Fingerprint.SequenceEqual(sha256)) ?? false
             },
         }
     };
     return model;
 }