org.bouncycastle.dvcs.SignedDVCSMessageGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcpkix-jdk15on Show documentation
Show all versions of bcpkix-jdk15on Show documentation
The Bouncy Castle Java APIs for CMS, PKCS, EAC, TSP, CMP, CRMF, OCSP, and certificate generation. This jar contains APIs for JDK 1.5 to JDK 1.8. The APIs can be used in conjunction with a JCE/JCA provider such as the one provided with the Bouncy Castle Cryptography APIs.
package org.bouncycastle.dvcs;
import java.io.IOException;
import org.bouncycastle.asn1.ASN1Encoding;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.cms.CMSProcessableByteArray;
import org.bouncycastle.cms.CMSSignedData;
import org.bouncycastle.cms.CMSSignedDataGenerator;
public class SignedDVCSMessageGenerator
{
private final CMSSignedDataGenerator signedDataGen;
public SignedDVCSMessageGenerator(CMSSignedDataGenerator signedDataGen)
{
this.signedDataGen = signedDataGen;
}
/**
* Creates a CMSSignedData object containing the passed in DVCSMessage
*
* @param message the request to be signed.
* @return an encapsulating SignedData object.
* @throws DVCSException in the event of failure to encode the request or sign it.
*/
public CMSSignedData build(DVCSMessage message)
throws DVCSException
{
try
{
byte[] encapsulatedData = message.getContent().toASN1Primitive().getEncoded(ASN1Encoding.DER);
return signedDataGen.generate(new CMSProcessableByteArray(message.getContentType(), encapsulatedData), true);
}
catch (CMSException e)
{
throw new DVCSException("Could not sign DVCS request", e);
}
catch (IOException e)
{
throw new DVCSException("Could not encode DVCS request", e);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy