Class CMSSignedData

java.lang.Object
org.bouncycastle.cms.CMSSignedData

public class CMSSignedData
extends Object
general class for handling a pkcs7-signature message. A simple example of usage - note, in the example below the validity of the certificate isn't verified, just the fact that one of the certs matches the given signer...
  Store                   certStore = s.getCertificates();
  SignerInformationStore  signers = s.getSignerInfos();
  Collection              c = signers.getSigners();
  Iterator                it = c.iterator();
  
  while (it.hasNext())
  {
      SignerInformation   signer = (SignerInformation)it.next();
      Collection          certCollection = certStore.getMatches(signer.getSID());

      Iterator              certIt = certCollection.iterator();
      X509CertificateHolder cert = (X509CertificateHolder)certIt.next();
  
      if (signer.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(cert)))
      {
          verified++;
      }   
  }
 
  • Constructor Details

  • Method Details

    • getVersion

      public int getVersion()
      Return the version number for this object
    • getSignerInfos

      public SignerInformationStore getSignerInfos()
      return the collection of signers that are associated with the signatures for the message.
    • getAttributeCertificates

      public X509Store getAttributeCertificates​(String type, String provider) throws NoSuchStoreException, NoSuchProviderException, CMSException
      Deprecated.
      use base Store returning method
      return a X509Store containing the attribute certificates, if any, contained in this message.
      Parameters:
      type - type of store to create
      provider - name of provider to use
      Returns:
      a store of attribute certificates
      Throws:
      NoSuchProviderException - if the provider requested isn't available.
      NoSuchStoreException - if the store type isn't available.
      CMSException - if a general exception prevents creation of the X509Store
    • getAttributeCertificates

      public X509Store getAttributeCertificates​(String type, Provider provider) throws NoSuchStoreException, CMSException
      Deprecated.
      use base Store returning method
      return a X509Store containing the attribute certificates, if any, contained in this message.
      Parameters:
      type - type of store to create
      provider - provider to use
      Returns:
      a store of attribute certificates
      Throws:
      NoSuchStoreException - if the store type isn't available.
      CMSException - if a general exception prevents creation of the X509Store
    • getCertificates

      public Store getCertificates()
      Return any X.509 certificate objects in this SignedData structure as a Store of X509CertificateHolder objects.
      Returns:
      a Store of X509CertificateHolder objects.
    • getCRLs

      public Store getCRLs()
      Return any X.509 CRL objects in this SignedData structure as a Store of X509CRLHolder objects.
      Returns:
      a Store of X509CRLHolder objects.
    • getAttributeCertificates

      public Store getAttributeCertificates()
      Return any X.509 attribute certificate objects in this SignedData structure as a Store of X509AttributeCertificateHolder objects.
      Returns:
      a Store of X509AttributeCertificateHolder objects.
    • getSignedContentTypeOID

      public String getSignedContentTypeOID()
      Return the a string representation of the OID associated with the encapsulated content info structure carried in the signed data.
      Returns:
      the OID for the content type.
    • getSignedContent

      public CMSTypedData getSignedContent()
    • getContentInfo

      public ContentInfo getContentInfo()
      Deprecated.
      use toASN1Structure()
      return the ContentInfo
    • toASN1Structure

      public ContentInfo toASN1Structure()
      return the ContentInfo
    • getEncoded

      public byte[] getEncoded() throws IOException
      return the ASN.1 encoded representation of this object.
      Throws:
      IOException
    • replaceSigners

      public static CMSSignedData replaceSigners​(CMSSignedData signedData, SignerInformationStore signerInformationStore)
      Replace the SignerInformation store associated with this CMSSignedData object with the new one passed in. You would probably only want to do this if you wanted to change the unsigned attributes associated with a signer, or perhaps delete one.
      Parameters:
      signedData - the signed data object to be used as a base.
      signerInformationStore - the new signer information store to use.
      Returns:
      a new signed data object.
    • replaceCertificatesAndCRLs

      public static CMSSignedData replaceCertificatesAndCRLs​(CMSSignedData signedData, CertStore certsAndCrls) throws CMSException
      Deprecated.
      use method taking Store arguments.
      Replace the certificate and CRL information associated with this CMSSignedData object with the new one passed in.
      Parameters:
      signedData - the signed data object to be used as a base.
      certsAndCrls - the new certificates and CRLs to be used.
      Returns:
      a new signed data object.
      Throws:
      CMSException - if there is an error processing the CertStore
    • replaceCertificatesAndCRLs

      public static CMSSignedData replaceCertificatesAndCRLs​(CMSSignedData signedData, Store certificates, Store attrCerts, Store crls) throws CMSException
      Replace the certificate and CRL information associated with this CMSSignedData object with the new one passed in.
      Parameters:
      signedData - the signed data object to be used as a base.
      certificates - the new certificates to be used.
      attrCerts - the new attribute certificates to be used.
      crls - the new CRLs to be used.
      Returns:
      a new signed data object.
      Throws:
      CMSException - if there is an error processing the CertStore