Example usage for org.bouncycastle.asn1.cms Attribute toASN1Primitive

List of usage examples for org.bouncycastle.asn1.cms Attribute toASN1Primitive

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.cms Attribute toASN1Primitive.

Prototype

public ASN1Primitive toASN1Primitive() 

Source Link

Document

Produce an object suitable for an ASN1OutputStream.

Usage

From source file:org.jmrtd.lds.SignedDataUtil.java

License:Open Source License

public static ASN1Set createAuthenticatedAttributes(String digestAlgorithm, String contentTypeOID,
        ContentInfo contentInfo) throws NoSuchAlgorithmException {
    /* Check bug found by Paulo Assumpco. */
    if ("SHA256".equals(digestAlgorithm)) {
        digestAlgorithm = "SHA-256";
    }/* w  ww .jav a 2s . co m*/
    MessageDigest dig = MessageDigest.getInstance(digestAlgorithm);
    byte[] contentBytes = ((DEROctetString) contentInfo.getContent()).getOctets();
    byte[] digestedContentBytes = dig.digest(contentBytes);
    ASN1OctetString digestedContent = new DEROctetString(digestedContentBytes);
    Attribute contentTypeAttribute = new Attribute(
            new ASN1ObjectIdentifier(SignedDataUtil.RFC_3369_CONTENT_TYPE_OID),
            createSingletonSet(new ASN1ObjectIdentifier(contentTypeOID)));
    Attribute messageDigestAttribute = new Attribute(
            new ASN1ObjectIdentifier(SignedDataUtil.RFC_3369_MESSAGE_DIGEST_OID),
            createSingletonSet(digestedContent));
    ASN1Object[] result = { contentTypeAttribute.toASN1Primitive(), messageDigestAttribute.toASN1Primitive() };
    return new DLSet(result);
}

From source file:org.signserver.module.mrtdsodsigner.jmrtd.SODFile.java

License:Open Source License

private static ASN1Set createAuthenticatedAttributes(String digestAlgorithm, byte[] contentBytes)
        throws NoSuchAlgorithmException {
    MessageDigest dig = MessageDigest.getInstance(digestAlgorithm);
    byte[] digestedContentBytes = dig.digest(contentBytes);
    ASN1OctetString digestedContent = new DEROctetString(digestedContentBytes);
    Attribute contentTypeAttribute = new Attribute(RFC_3369_CONTENT_TYPE_OID, createSingletonSet(ICAO_SOD_OID));
    Attribute messageDigestAttribute = new Attribute(RFC_3369_MESSAGE_DIGEST_OID,
            createSingletonSet(digestedContent));
    ASN1Encodable[] result = { contentTypeAttribute.toASN1Primitive(),
            messageDigestAttribute.toASN1Primitive() };
    return new DERSet(result);
}