public string GetPublicKey()
 {
     return(EncodingUtility.ExtractModulus(EncodingUtility.DeBase64RSAKey(Certificate.PublicKey.Key.ToXmlString(false))));
 }
        public void Begin()
        {
            if (CancelToken.IsCancellationRequested)
            {
                return;
            }

            FilePaths = SearchExtensions.SelectMany(searchPattern => Directory.EnumerateFiles(SearchDirectory, searchPattern, SearchOption.TopDirectoryOnly));
            //FilePaths = Directory.EnumerateFiles(SearchDirectory, SearchExtension, SearchOption.TopDirectoryOnly);

            if (FilePaths == null)
            {
                throw new Exception("No files to process!");
            }

            byte[]         bytes   = new byte[] { };
            ANS1PrivateKey ans1Key = null;
            StringBuilder  output  = new StringBuilder();

            List <string> filesToDelete = new List <string>();

            IEnumerable <string> pathBatch = FilePaths.Take(BatchSize);

            while (pathBatch.Any() && !CancelToken.IsCancellationRequested)
            {
                foreach (string file in pathBatch)
                {
                    bytes = GetEncodedBytes(file);

                    if (bytes == null)
                    {
                        continue;
                    }
                    else if (bytes == EmptyByteArray)
                    {
                        if (DeleteFiles)
                        {
                            filesToDelete.Add(file);
                        }
                    }

                    using (ans1Key = new ANS1PrivateKey(bytes))
                    {
                        ans1Key.ParseBuffer();

                        EncodingUtility.AssertValidRSAPrivateKey(ans1Key);

                        if (ExportOnlyPQ)
                        {
                            PrivateKeySerializer.WritePQDocument(output, ans1Key);
                        }
                        else
                        {
                            PrivateKeySerializer.WriteXMLDocument(output, ans1Key);
                        }

                        bytes = null;

                        if (DeleteFiles)
                        {
                            filesToDelete.Add(file);
                        }
                    }
                }

                File.AppendAllText(OutputFilename, output.ToString());
                output.Clear();
                bytes = null;

                if (DeleteFiles && filesToDelete.Any())
                {
                    foreach (string file in filesToDelete)
                    {
                        File.Delete(file);
                    }
                    filesToDelete.Clear();
                }

                FilePaths = FilePaths.Skip(BatchSize);
                pathBatch = FilePaths.Take(BatchSize);
            }
        }