private static int AddSignCades(AddSignCadesOptions opts)
        {
            string eidLib = string.IsNullOrEmpty(opts.LibPath) ? FindEidLibrary() : opts.LibPath;

            Console.WriteLine("Load: {0}", eidLib);
            using CardDeviceController cardDeviceController = new CardDeviceController(eidLib, CreatePinprovider(opts.UseAppPinInput));
            CardSigningCertificate signedCertificate = cardDeviceController.GetSignedCertificates().Single();

            using X509Certificate2 certificate = signedCertificate.GetCertificate();
            Console.WriteLine("Signing certificate with subject: {0}", certificate.Subject);

            ICadesExternalSignature externalSignature = new CadesExternalSignature(signedCertificate);
            ExtendedCadesSigner     signer            = new ExtendedCadesSigner(opts.ContainerFile);

            if (!string.IsNullOrEmpty(opts.SourceFile))
            {
                string mimeType = string.IsNullOrEmpty(opts.SourceFileMimeType) ? MimeType.GetMimeTypeFromFileName(Path.GetFileName(opts.SourceFile)) : opts.SourceFileMimeType;
                signer.AddFile(new FileInfo(opts.SourceFile), mimeType);
            }

            signer.CreateContainer(externalSignature, opts.DestinationFile);

            Console.WriteLine("Add signature to {0} and saved to {1}", Path.GetFileName(opts.ContainerFile), opts.DestinationFile);

            return(0);
        }
        private static int ListCertificates(ListCertOptions opts)
        {
            string eidLib = string.IsNullOrEmpty(opts.LibPath) ? FindEidLibrary() : opts.LibPath;

            Console.WriteLine("Load: {0}", eidLib);
            Console.WriteLine("Certificates:");
            Console.WriteLine();

            using (CardDeviceController cardDeviceController = new CardDeviceController(eidLib, CreatePinprovider(opts.UseAppPinInput), opts.ListEp ? "SIG_EP" : "SIG_ZEP"))
            {
                foreach (X509Certificate2 certificate in cardDeviceController.ListCertificates())
                {
                    Console.WriteLine(OutputCertFormater.Format(certificate, opts.OutputFormat));
                }
            }

            return(0);
        }
        private static int SignPdf(SignPdfOptions opts)
        {
            string eidLib = string.IsNullOrEmpty(opts.LibPath) ? FindEidLibrary() : opts.LibPath;

            Console.WriteLine("Load: {0}", eidLib);
            using CardDeviceController cardDeviceController = new CardDeviceController(eidLib, CreatePinprovider(opts.UseAppPinInput));
            CardSigningCertificate signedCertificate = cardDeviceController.GetSignedCertificates().Single();

            using X509Certificate2 certificate = signedCertificate.GetCertificate();
            Console.WriteLine("Signing certificate with subject: {0}", certificate.Subject);

            Pkcs11ExternalSignature pkcs11ExternalSignature = new Pkcs11ExternalSignature(signedCertificate);

            PdfSignerHelper.Sign(pkcs11ExternalSignature,
                                 certificate,
                                 opts.SourcePdf,
                                 opts.DestinationFile);

            Console.WriteLine("{0} signed and saved to {1}", Path.GetFileName(opts.SourcePdf), opts.DestinationFile);

            return(0);
        }