Example usage for org.bouncycastle.asn1.esf SignaturePolicyId SignaturePolicyId

List of usage examples for org.bouncycastle.asn1.esf SignaturePolicyId SignaturePolicyId

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.esf SignaturePolicyId SignaturePolicyId.

Prototype

public SignaturePolicyId(ASN1ObjectIdentifier sigPolicyIdentifier, OtherHashAlgAndValue sigPolicyHash) 

Source Link

Usage

From source file:eu.europa.ec.markt.dss.signature.cades.CAdESLevelBaselineB.java

License:Open Source License

private void addSignaturePolicyId(final SignatureParameters parameters,
        final ASN1EncodableVector signedAttributes) {

    Policy policy = parameters.bLevel().getSignaturePolicy();
    if (policy != null && policy.getId() != null) {

        final String policyId = policy.getId();
        SignaturePolicyIdentifier sigPolicy = null;
        if (!"".equals(policyId)) { // explicit

            final ASN1ObjectIdentifier derOIPolicyId = new ASN1ObjectIdentifier(policyId);
            final ASN1ObjectIdentifier oid = policy.getDigestAlgorithm().getOid();
            final AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(oid);
            OtherHashAlgAndValue otherHashAlgAndValue = new OtherHashAlgAndValue(algorithmIdentifier,
                    new DEROctetString(policy.getDigestValue()));
            sigPolicy = new SignaturePolicyIdentifier(
                    new SignaturePolicyId(derOIPolicyId, otherHashAlgAndValue));
        } else {// implicit
            sigPolicy = new SignaturePolicyIdentifier();
        }/* w ww . j av  a 2  s  . co m*/
        final DERSet attrValues = new DERSet(sigPolicy);
        final Attribute attribute = new Attribute(PKCSObjectIdentifiers.id_aa_ets_sigPolicyId, attrValues);
        signedAttributes.add(attribute);
    }
}

From source file:eu.europa.ec.markt.dss.signature.cades.CAdESProfileEPES.java

License:Open Source License

@Override
public Hashtable<ASN1ObjectIdentifier, ASN1Encodable> getSignedAttributes(SignatureParameters parameters) {

    try {// w w  w  .  ja  va2s .c  om

        Hashtable<ASN1ObjectIdentifier, ASN1Encodable> signedAttrs = super.getSignedAttributes(parameters);

        Attribute policy = null;
        SignaturePolicyIdentifier sigPolicy = null;
        switch (parameters.getSignaturePolicy()) {
        case EXPLICIT:
            sigPolicy = new SignaturePolicyIdentifier(
                    new SignaturePolicyId(new DERObjectIdentifier(parameters.getSignaturePolicyId()),
                            new OtherHashAlgAndValue(
                                    new AlgorithmIdentifier(DigestAlgorithm
                                            .getByName(parameters.getSignaturePolicyHashAlgo()).getOid()),
                                    new DEROctetString(parameters.getSignaturePolicyHashValue()))));
            policy = new Attribute(PKCSObjectIdentifiers.id_aa_ets_sigPolicyId, new DERSet(sigPolicy));
            signedAttrs.put(PKCSObjectIdentifiers.id_aa_ets_sigPolicyId, policy);
            break;
        case IMPLICIT:
            sigPolicy = new SignaturePolicyIdentifier();
            sigPolicy.isSignaturePolicyImplied();
            policy = new Attribute(PKCSObjectIdentifiers.id_aa_ets_sigPolicyId, new DERSet(sigPolicy));
            signedAttrs.put(PKCSObjectIdentifiers.id_aa_ets_sigPolicyId, policy);
            break;
        case NO_POLICY:
            break;
        }

        return signedAttrs;
    } catch (NoSuchAlgorithmException ex) {
        throw new ProfileException(ex.getMessage());
    }

}