title: My code can verify self signed certificate but is failing when VeriSign issued certificate is used
body: <p>My application is using java security APIs to sign a file and verify it.
  While signing , I am using PFX file and password as inputs and after signing I am generating a signature file using the bytes.
  While verification process I am using signature file ,certificate file and the signed file as inputs.
  Please find the code I am using in verification below:</p>
  
  <pre><code> // KeyFilePath= path of certificate file
   // fileToVerify = path of signed file
   // signatureFilePath = path of signature file
  
  
  
   InputStream inputStream = new FileInputStream(KeyFilePath);
   CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
   X509Certificate x509Certificate = (X509Certificate) certificateFactory.generateCertificate(inputStream);
  
   // input the signature bytes
   String sigFile = signatureFilePath;
  
   FileInputStream sigFileInputStream = new FileInputStream(sigFile);
   byte[] sigToVerify = new byte[sigFileInputStream.available()];
   sigFileInputStream.read(sigToVerify);
   sigFileInputStream.close();
  
   PublicKey pubKey = x509Certificate.getPublicKey();
   Signature signature = Signature.getInstance(signAlgorithm);
  
   signature.initVerify(pubKey);
  
   // Update and verify the data
   try {
      FileInputStream dataFileInputStream = new FileInputStream(fileToVerify);
      BufferedInputStream bufferedInputStream = new BufferedInputStream(dataFileInputStream);
  
      byte[] buffer = new byte[IVerifyDigitalSignature.BYTE_SIZE];
      int bufferedInputStreamLength;
  
      while (bufferedInputStream.available() != IVerifyDigitalSignature.ZERO_LENGTH) {
          bufferedInputStreamLength = bufferedInputStream.read(buffer);
          signature.update(buffer, IVerifyDigitalSignature.ZERO_LENGTH, bufferedInputStreamLength);
      }
  
      bufferedInputStream.close();
  
      // Verify the Signature
      x509Certificate.verify(pubKey);
      verifyDigitalSignature = signature.verify(sigToVerify);
  </code></pre>
  
  <p>Please help me in resolving the same as it is yet not closed.</p>