Example usage for org.bouncycastle.cms CMSAttributeTableGenerator DIGEST

List of usage examples for org.bouncycastle.cms CMSAttributeTableGenerator DIGEST

Introduction

In this page you can find the example usage for org.bouncycastle.cms CMSAttributeTableGenerator DIGEST.

Prototype

String DIGEST

To view the source code for org.bouncycastle.cms CMSAttributeTableGenerator DIGEST.

Click Source Link

Usage

From source file:org.demoiselle.signer.policy.impl.cades.pkcs7.impl.DemoiselleSignedAttributeTableGenerator.java

License:Open Source License

/**
 * Create a standard attribute table from the passed in parameters - this will
 * normally include contentType, signingTime, and messageDigest. If the constructor
 * using an AttributeTable was used, entries in it for contentType, signingTime, and
 * messageDigest will override the generated ones.
 *
 * @param parameters source parameters for table generation.
 *
 * @return a filled in Hashtable of attributes.
 */// ww  w . ja  v a2  s.c o  m
protected Hashtable createStandardAttributeTable(Map parameters) {
    Hashtable std = copyHashTable(table);

    if (!std.containsKey(CMSAttributes.contentType)) {
        ASN1ObjectIdentifier contentType = ASN1ObjectIdentifier
                .getInstance(parameters.get(CMSAttributeTableGenerator.CONTENT_TYPE));

        // contentType will be null if we're trying to generate a counter signature.
        if (contentType != null) {
            Attribute attr = new Attribute(CMSAttributes.contentType, new DERSet(contentType));
            std.put(attr.getAttrType(), attr);
        }
    }

    if (!std.containsKey(CMSAttributes.messageDigest)) {
        byte[] messageDigest = (byte[]) parameters.get(CMSAttributeTableGenerator.DIGEST);
        Attribute attr = new Attribute(CMSAttributes.messageDigest,
                new DERSet(new DEROctetString(messageDigest)));
        std.put(attr.getAttrType(), attr);
    }

    return std;
}