title: Bouncycastle CMSException
body: <p>Why bouncycastle Exception is thrown when data format is correct.                        </p>
  
  <pre><code>@SuppressWarnings({ "rawtypes", "deprecation"}) 
       public static boolean verifySign(String base64Data, String base64SignedData)
                   throws Exception {
           /* to add BouncyCastleProvider */
             Security.addProvider(new BouncyCastleProvider());
             /* to add BouncyCastleProvider end */
             boolean verifiedStatus = false; 
             CMSSignedData cmsSignedData = null;
             X509Certificate cert = null;
          //   LOGGER.info("Entering verifySign at {}", System.currentTimeMillis());
             System.out.println("Entering verifySign at {}"+System.currentTimeMillis());  
             try { 
                  // LOGGER.debug("base64Data and base64SignedData {} ", base64Data,    base64SignedData);
                   System.out.println("base64Data {}="+base64Data);
                   System.out.println(" base64SignedData{}="+ base64SignedData);   
                   byte[] signedBytes = Base64.decodeBase64(base64SignedData);
       cmsSignedData = new CMSSignedData(  new CMSProcessableByteArray(base64Data.getBytes()),signedBytes);
  
                   CertStore certStore = cmsSignedData.getCertificatesAndCRLs("Collection", "BC");
                   Collection signers = cmsSignedData.getSignerInfos().getSigners();
                   Iterator signersIterator = signers.iterator();
                   while (signersIterator.hasNext()) {
                         SignerInformation signer = (SignerInformation) signersIterator.next();
                         Collection certCollection = certStore.getCertificates(signer.getSID());
                         Iterator certIt = certCollection.iterator(); 
                         cert = (X509Certificate) certIt.next();
                         System.out.println("public key"+cert.getPublicKey());
                         verifiedStatus = signer.verify(cert.getPublicKey(), "BC");  
                   }
                  // LOGGER.debug("Signature verification status {} ", verifiedStatus);
                   System.out.println("Signature verification status {} ::"+ verifiedStatus);
             } catch (CMSException cmse) {
                  // LOGGER.error("CMSException in verifySign", cmse);
                   System.out.println("CMSException in verifySign"+cmse);
                   throw cmse; 
             } catch (Exception e) {
                   //LOGGER.error("Exception in verifySign", e);
                   System.out.println("Exception in verifySign"+e);
                   throw e;
             } finally {
                 //  LOGGER.info("Exiting verifySign at {}", System.currentTimeMillis());
                   System.out.println("Exiting verifySign at {}"+System.currentTimeMillis());
             }
             return verifiedStatus;
       }
  </code></pre>
  
  <p>A <code>CMSException</code> is thrown in <code>verifySign</code>:</p>
  
  <pre><code>org.bouncycastle.cms.CMSSignerDigestMismatchException:
  message-digest attribute value does not match calculated value
  Exiting verifySign at {}1495630515140
  Exception in thread "main" org.bouncycastle.cms.CMSSignerDigestMismatchException:
  message-digest attribute value does not match calculated value
      at org.bouncycastle.cms.SignerInformation.doVerify(Unknown Source)
      at org.bouncycastle.cms.SignerInformation.verify(Unknown Source)
      at org.bouncycastle.cms.SignerInformation.verify(Unknown Source)
  </code></pre>