/// <summary>
        ///     Define o PIN para chave privada de um objeto <see cref="X509Certificate2" /> passado no parâmetro
        /// </summary>
        private static void DefinirPinParaChavePrivada(this X509Certificate2 certificado, string pin)
        {
            Guard.Against <ArgumentNullException>(certificado.IsNull(), "Certificado não informado");

            var key = (RSACryptoServiceProvider)certificado.PrivateKey;

            var providerHandle = IntPtr.Zero;
            var pinBuffer      = Encoding.ASCII.GetBytes(pin);

            MetodosNativos.Executar(() => MetodosNativos.CryptAcquireContext(ref providerHandle,
                                                                             key.CspKeyContainerInfo.KeyContainerName,
                                                                             key.CspKeyContainerInfo.ProviderName,
                                                                             key.CspKeyContainerInfo.ProviderType,
                                                                             MetodosNativos.CryptContextFlags.Silent));
            MetodosNativos.Executar(() => MetodosNativos.CryptSetProvParam(providerHandle,
                                                                           MetodosNativos.CryptParameter.KeyExchangePin,
                                                                           pinBuffer, 0));
            MetodosNativos.Executar(() => MetodosNativos.CertSetCertificateContextProperty(
                                        certificado.Handle,
                                        MetodosNativos.CertificateProperty.CryptoProviderHandle,
                                        0, providerHandle));
        }
        /// <summary>
        /// Seta a senha do certificado digital A3
        /// Observação: Obter o certificado digital do repositorio com "OpenFlags.ReadOnly"
        /// </summary>
        /// <param name="x509Certificate2"></param>
        /// <param name="senha"></param>
        public static void SetSenhaA3(this X509Certificate2 x509Certificate2, string senha)
        {
            if (x509Certificate2 == null)
            {
                throw new ArgumentNullException(nameof(x509Certificate2));
            }
            var key = (RSACryptoServiceProvider)x509Certificate2.PrivateKey;

            var providerHandle = IntPtr.Zero;
            var pinBuffer      = Encoding.ASCII.GetBytes(senha);

            MetodosNativos.Executar(() => MetodosNativos.CryptAcquireContext(ref providerHandle,
                                                                             key.CspKeyContainerInfo.KeyContainerName,
                                                                             key.CspKeyContainerInfo.ProviderName,
                                                                             key.CspKeyContainerInfo.ProviderType,
                                                                             MetodosNativos.CryptContextFlags.Silent));
            MetodosNativos.Executar(() => MetodosNativos.CryptSetProvParam(providerHandle,
                                                                           MetodosNativos.CryptParameter.KeyExchangePin,
                                                                           pinBuffer, 0));
            MetodosNativos.Executar(() => MetodosNativos.CertSetCertificateContextProperty(
                                        x509Certificate2.Handle,
                                        MetodosNativos.CertificateProperty.CryptoProviderHandle,
                                        0, providerHandle));
        }