title: Compilation error while verifying the signature in bouncycastle java
body: <p>I would like to ask about this exception: </p>
  
  <pre><code>java.lang.ClassCastException: org.bouncycastle.cms.SignerId cannot be cast to java.security.cert.CertSelector
      at tn.ance.signature.VerificationSignature.verifierSignature(VerificationSignature.java:27)
      at tn.ance.signature.main_project.main(main_project.java:24)
  </code></pre>
  
  <p>here is my class VerificationSignature</p>
  
  <pre><code>package tn.ance.signature;
  import java.io.*;
  import java.util.*;
  import java.security.cert.CertSelector;
  import java.security.cert.CertStore;
  import java.security.cert.X509Certificate;
  
  import org.bouncycastle.cms.CMSSignedData;
  import org.bouncycastle.cms.CMSProcessable;
  import org.bouncycastle.cms.SignerInformation;
  
  
  public class VerificationSignature {
  
      public void verifierSignature(){
          try {
              // Chargement du fichier signé
              File f = new File("fichier_a_signer.txt.pk7");
              byte[] buffer = new byte[(int)f.length()];
              DataInputStream in = new DataInputStream(new FileInputStream(f));
              in.readFully(buffer);
              in.close();
  
              CMSSignedData signature = new CMSSignedData(buffer);
              SignerInformation signer = (SignerInformation)signature.getSignerInfos().getSigners().iterator().next();
              CertStore cs = signature.getCertificatesAndCRLs("Collection", "BC");
              Iterator iter = cs.getCertificates((CertSelector) signer.getSID()).iterator();
              X509Certificate certificate = (X509Certificate) iter.next();
              CMSProcessable sc = signature.getSignedContent();
              byte[] data = (byte[]) sc.getContent();
  
              // Verifie la signature
              System.out.println(signer.verify(certificate, "BC"));
  
              FileOutputStream envfos = new FileOutputStream("document_non_signer.txt");
              envfos.write(data);
              envfos.close();
              System.out.println("Verification signature: done!");
          } catch (Exception e) {
              e.printStackTrace();
              System.out.println("Verification signature: error!");
              return ;
          }
  }
  }
  </code></pre>
  
  <p>The error comes from this line </p>
  
  <pre><code>        SignerInformation signer = (SignerInformation)signature.getSignerInfos().getSigners().iterator().next();
  </code></pre>
  
  <p>but I didn't know how to fix it. Any help please? I am totally new to the bouncycastle library!</p>