Class CMSUtils


  • public final class CMSUtils
    extends Object
    • Method Summary

      Modifier and Type Method Description
      static void addSigningCertificateAttribute​(org.bouncycastle.asn1.ASN1EncodableVector signedAttributes, DigestAlgorithm digestAlgorithm, CertificateToken signingToken)
      Method to add signing certificate to ASN.1 DER encoded signed attributes.
      static org.bouncycastle.cms.CMSSignedData generateCMSSignedData​(org.bouncycastle.cms.CMSSignedDataGenerator generator, org.bouncycastle.cms.CMSTypedData content, boolean encapsulate)
      This method generate CMSSignedData using the provided #CMSSignedDataGenerator, the content and the indication if the content should be encapsulated.
      static org.bouncycastle.cms.CMSSignedData generateDetachedCMSSignedData​(org.bouncycastle.cms.CMSSignedDataGenerator generator, org.bouncycastle.cms.CMSProcessableByteArray content)  
      static org.bouncycastle.asn1.cms.AttributeTable getAttributesFromByteArray​(byte[] encodedAttributes)
      This method returns an AttributeTable parsed from ASN.1 encoded representation
      static org.bouncycastle.cms.CMSTypedData getContentToBeSign​(DSSDocument toSignData)  
      static org.bouncycastle.asn1.DERTaggedObject getDERSignedAttributes​(org.bouncycastle.cms.SignerInformation signerInformation)  
      static DSSDocument getOriginalDocument​(org.bouncycastle.cms.CMSSignedData cmsSignedData, List<DSSDocument> detachedDocuments)
      Returns the original document from the provided cmsSignedData
      static org.bouncycastle.asn1.cms.AttributeTable getSignedAttributes​(org.bouncycastle.cms.SignerInformation signerInformation)
      This method returns the existing signed attributes or a new empty attributes hashtable
      static byte[] getSignedContent​(org.bouncycastle.cms.CMSTypedData cmsTypedData)
      This method returns the signed content extracted from a CMSTypedData
      static org.bouncycastle.asn1.cms.Attribute getUnsignedAttribute​(org.bouncycastle.cms.SignerInformation signerInformation, org.bouncycastle.asn1.ASN1ObjectIdentifier oid)
      Returns an unsigned attribute by its given oid
      static org.bouncycastle.asn1.cms.AttributeTable getUnsignedAttributes​(org.bouncycastle.cms.SignerInformation signerInformation)
      This method returns the existing unsigned attributes or a new empty attributes hashtable
      static boolean isDetachedSignature​(org.bouncycastle.cms.CMSSignedData cmsSignedData)
      Checks if the signature is detached
      static org.bouncycastle.asn1.cms.AttributeTable replaceAttribute​(org.bouncycastle.asn1.cms.AttributeTable attributeTable, org.bouncycastle.cms.CMSSignedData attributeToReplace, org.bouncycastle.cms.CMSSignedData attributeToAdd)
      Returns a new AttributeTable with replaced attributeToReplace by attributeToAdd
    • Field Detail

      • DEFAULT_ARCHIVE_TIMESTAMP_HASH_ALGO

        public static final DigestAlgorithm DEFAULT_ARCHIVE_TIMESTAMP_HASH_ALGO
    • Method Detail

      • generateCMSSignedData

        public static org.bouncycastle.cms.CMSSignedData generateCMSSignedData​(org.bouncycastle.cms.CMSSignedDataGenerator generator,
                                                                               org.bouncycastle.cms.CMSTypedData content,
                                                                               boolean encapsulate)
        This method generate CMSSignedData using the provided #CMSSignedDataGenerator, the content and the indication if the content should be encapsulated.
        Parameters:
        generator -
        content -
        encapsulate -
        Returns:
      • generateDetachedCMSSignedData

        public static org.bouncycastle.cms.CMSSignedData generateDetachedCMSSignedData​(org.bouncycastle.cms.CMSSignedDataGenerator generator,
                                                                                       org.bouncycastle.cms.CMSProcessableByteArray content)
                                                                                throws DSSException
        Throws:
        DSSException
      • getDERSignedAttributes

        public static org.bouncycastle.asn1.DERTaggedObject getDERSignedAttributes​(org.bouncycastle.cms.SignerInformation signerInformation)
        Parameters:
        signerInformation - SignerInformation
        Returns:
        DERTaggedObject representing the signed attributes
      • getSignedContent

        public static byte[] getSignedContent​(org.bouncycastle.cms.CMSTypedData cmsTypedData)
        This method returns the signed content extracted from a CMSTypedData
        Parameters:
        cmsTypedData - CMSTypedData cannot be null
        Returns:
        the signed content extracted from CMSTypedData
      • getUnsignedAttributes

        public static org.bouncycastle.asn1.cms.AttributeTable getUnsignedAttributes​(org.bouncycastle.cms.SignerInformation signerInformation)
        This method returns the existing unsigned attributes or a new empty attributes hashtable
        Parameters:
        signerInformation - the signer information
        Returns:
        the existing unsigned attributes or an empty attributes hashtable
      • getSignedAttributes

        public static org.bouncycastle.asn1.cms.AttributeTable getSignedAttributes​(org.bouncycastle.cms.SignerInformation signerInformation)
        This method returns the existing signed attributes or a new empty attributes hashtable
        Parameters:
        signerInformation - the signer information
        Returns:
        the existing signed attributes or an empty attributes Hashtable
      • getAttributesFromByteArray

        public static org.bouncycastle.asn1.cms.AttributeTable getAttributesFromByteArray​(byte[] encodedAttributes)
        This method returns an AttributeTable parsed from ASN.1 encoded representation
        Parameters:
        encodedAttributes - ASN.1 encoded AttributesTable
        Returns:
        AttributeTable created from given encodedAttributes
      • addSigningCertificateAttribute

        public static void addSigningCertificateAttribute​(org.bouncycastle.asn1.ASN1EncodableVector signedAttributes,
                                                          DigestAlgorithm digestAlgorithm,
                                                          CertificateToken signingToken)
        Method to add signing certificate to ASN.1 DER encoded signed attributes. Certificate will be added as either signing-certificate or signing-certificate-v2 attribute depending on digest algorithm being used.
        Parameters:
        signedAttributes - Signed attributes to append signing certificate to
        digestAlgorithm - the digest algorithm to be used
        signingToken - The signing certificate to be append
      • replaceAttribute

        public static org.bouncycastle.asn1.cms.AttributeTable replaceAttribute​(org.bouncycastle.asn1.cms.AttributeTable attributeTable,
                                                                                org.bouncycastle.cms.CMSSignedData attributeToReplace,
                                                                                org.bouncycastle.cms.CMSSignedData attributeToAdd)
                                                                         throws IOException,
                                                                                org.bouncycastle.cms.CMSException
        Returns a new AttributeTable with replaced attributeToReplace by attributeToAdd
        Parameters:
        attributeTable - AttributeTable to replace value in
        attributeToReplace - CMSSignedData to be replaced
        attributeToAdd - CMSSignedData to replace by
        Returns:
        a new AttributeTable
        Throws:
        IOException - in case of encoding error
        org.bouncycastle.cms.CMSException - in case of CMSException
      • getUnsignedAttribute

        public static org.bouncycastle.asn1.cms.Attribute getUnsignedAttribute​(org.bouncycastle.cms.SignerInformation signerInformation,
                                                                               org.bouncycastle.asn1.ASN1ObjectIdentifier oid)
        Returns an unsigned attribute by its given oid
        Parameters:
        signerInformation - SignerInformation to get attribute from
        oid - ASN1ObjectIdentifier of the target attribute
        Returns:
        Attribute
      • isDetachedSignature

        public static boolean isDetachedSignature​(org.bouncycastle.cms.CMSSignedData cmsSignedData)
        Checks if the signature is detached
        Parameters:
        cmsSignedData - CMSSignedData
        Returns:
        TRUE if the signature is detached, FALSE otherwise
      • getOriginalDocument

        public static DSSDocument getOriginalDocument​(org.bouncycastle.cms.CMSSignedData cmsSignedData,
                                                      List<DSSDocument> detachedDocuments)
        Returns the original document from the provided cmsSignedData
        Parameters:
        cmsSignedData - CMSSignedData to get original document from
        Returns:
        original DSSDocument
      • getContentToBeSign

        public static org.bouncycastle.cms.CMSTypedData getContentToBeSign​(DSSDocument toSignData)