Search in sources :

Example 21 with PKIHeader

use of com.github.zhenwei.pkix.util.asn1.cmp.PKIHeader in project LinLong-Java by zhenwei1108.

the class ProtectedPKIMessageBuilder method build.

/**
 * Build a protected PKI message which has MAC based integrity protection.
 *
 * @param signer the ContentSigner to be used to calculate the signature.
 * @return the resulting protected PKI message.
 * @throws CMPException if the protection signature cannot be calculated.
 */
public ProtectedPKIMessage build(ContentSigner signer) throws CMPException {
    if (null == body) {
        throw new IllegalStateException("body must be set before building");
    }
    finaliseHeader(signer.getAlgorithmIdentifier());
    PKIHeader header = hdrBuilder.build();
    try {
        DERBitString protection = new DERBitString(calculateSignature(signer, header, body));
        return finaliseMessage(header, protection);
    } catch (IOException e) {
        throw new CMPException("unable to encode signature input: " + e.getMessage(), e);
    }
}
Also used : PKIHeader(com.github.zhenwei.pkix.util.asn1.cmp.PKIHeader) DERBitString(com.github.zhenwei.core.asn1.DERBitString) IOException(java.io.IOException)

Aggregations

PKIHeader (org.bouncycastle.asn1.cmp.PKIHeader)19 PKIBody (org.bouncycastle.asn1.cmp.PKIBody)13 PKIMessage (org.bouncycastle.asn1.cmp.PKIMessage)12 ProtectedPKIMessage (org.bouncycastle.cert.cmp.ProtectedPKIMessage)9 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)8 IOException (java.io.IOException)6 GeneralPKIMessage (org.bouncycastle.cert.cmp.GeneralPKIMessage)6 DEROctetString (org.bouncycastle.asn1.DEROctetString)5 InfoTypeAndValue (org.bouncycastle.asn1.cmp.InfoTypeAndValue)4 GeneralName (org.bouncycastle.asn1.x509.GeneralName)4 CMPException (org.bouncycastle.cert.cmp.CMPException)4 ProtectionVerificationResult (org.xipki.cmp.ProtectionVerificationResult)4 InvalidKeyException (java.security.InvalidKeyException)3 Date (java.util.Date)3 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)3 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)3 PKIFreeText (org.bouncycastle.asn1.cmp.PKIFreeText)3 ContentVerifierProvider (org.bouncycastle.operator.ContentVerifierProvider)3 OperatorCreationException (org.bouncycastle.operator.OperatorCreationException)3 DERBitString (com.github.zhenwei.core.asn1.DERBitString)2