Exemplo n.º 1
0
 public static bool ExistsKeyContainer(this CryExpander exp)
 {
     try
     {
         return(FindSignerCertificate() != null);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 2
0
        public static X509Certificate2 FindSignerCertInKeyContainer(this CryExpander exp, X509Certificate2 certificate)
        {
            if (certificate == null)
            {
                return(null);
            }
            var certificateKey = certificate.PublicKey.EncodedKeyValue.RawData;
            var containers     = GetContainers();

            foreach (var container in containers)
            {
                var containerKey = GetPublicKeyOfContainer(container);
                if (Je.bin.IsEqualBytes(containerKey, certificateKey))
                {
                    return(certificate);
                }
            }
            return(null);
        }
Exemplo n.º 3
0
        public static X509Certificate2 FindCertificateByThumbprint(this CryExpander exp, string thumbprint)
        {
            thumbprint = (thumbprint ?? string.Empty).ToUpper();
            if (string.IsNullOrWhiteSpace(thumbprint))
            {
                return(null);
            }
            var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);

            store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);
            try
            {
                var thumbprintBytes = Encoding.UTF8.GetBytes(thumbprint.ToUpper());
                var cert            = FindCertificateByThumbprint(store, thumbprintBytes);
                if (cert != null)
                {
                    return(cert);
                }

                thumbprintBytes = RemovePreamble(thumbprintBytes);
                cert            = FindCertificateByThumbprint(store, thumbprintBytes);
                if (cert != null)
                {
                    return(cert);
                }

                thumbprintBytes = RemovePreamble(thumbprintBytes);
                cert            = FindCertificateByThumbprint(store, thumbprintBytes);
                return(cert);
            }
            catch
            {
                return(null);
            }
            finally
            {
                store.Close();
            }
        }