Java 类org.bouncycastle.asn1.ess.ContentIdentifier 实例源码

项目:dss    文件:CAdESSignature.java   
@Override
public String getContentIdentifier() {
    final Attribute contentIdentifierAttribute = getSignedAttribute(PKCSObjectIdentifiers.id_aa_contentIdentifier);
    if (contentIdentifierAttribute == null) {
        return null;
    }
    final ASN1Encodable asn1Encodable = contentIdentifierAttribute.getAttrValues().getObjectAt(0);
    final ContentIdentifier contentIdentifier = ContentIdentifier.getInstance(asn1Encodable);
    final String contentIdentifierString = DSSASN1Utils.toString(contentIdentifier.getValue());
    return contentIdentifierString;
}
项目:dss    文件:CAdESLevelBaselineB.java   
/**
 * ETSI TS 101 733 V2.2.1 (2013-04)
 *
 * 5.10.2 content-identifier Attribute
 * The content-identifier attribute provides an identifier for the signed content, for use when a reference may be
 * later required to that content; for example, in the content-reference attribute in other signed data sent later.
 * The
 * content-identifier shall be a signed attribute. content-identifier attribute type values for the ES have an ASN.1
 * type ContentIdentifier, as defined in
 * ESS (RFC 2634 [5]).
 *
 * The minimal content-identifier attribute should contain a concatenation of user-specific identification
 * information (such as a user name or public keying material identification information), a GeneralizedTime string,
 * and a random number.
 *
 * @param parameters
 * @param signedAttributes
 */
private void addContentIdentifier(final CAdESSignatureParameters parameters, final ASN1EncodableVector signedAttributes) {

    /* this attribute is prohibited in PAdES B */
    if (!padesUsage) {

        final String contentIdentifierPrefix = parameters.getContentIdentifierPrefix();
        if (Utils.isStringNotBlank(contentIdentifierPrefix)) {

            final String contentIdentifierSuffix;
            if (Utils.isStringBlank(parameters.getContentIdentifierSuffix())) {

                final Date now = new Date();
                final String asn1GeneralizedTimeString = new ASN1GeneralizedTime(now).getTimeString();
                final long randomNumber = new Random(now.getTime()).nextLong();
                contentIdentifierSuffix = asn1GeneralizedTimeString + randomNumber;
                parameters.setContentIdentifierSuffix(contentIdentifierSuffix);
            } else {
                contentIdentifierSuffix = parameters.getContentIdentifierSuffix();
            }
            final String contentIdentifierString = contentIdentifierPrefix + contentIdentifierSuffix;
            final ContentIdentifier contentIdentifier = new ContentIdentifier(contentIdentifierString.getBytes());
            final DERSet attrValues = new DERSet(contentIdentifier);
            final Attribute attribute = new Attribute(id_aa_contentIdentifier, attrValues);
            signedAttributes.add(attribute);
        }
    }
}