public PkiMessage( PkiHeader header, PkiBody body, DerBitString protection) : this(header, body, protection, null) { }
private byte[] CalculateSignature(IStreamCalculator signer, PkiHeader header, PkiBody body) { Asn1EncodableVector avec = new Asn1EncodableVector(); avec.Add(header); avec.Add(body); byte[] encoded = new DerSequence(avec).GetEncoded(); signer.Stream.Write(encoded, 0, encoded.Length); Object result = signer.GetResult(); if (result is DefaultSignatureResult) { return(((DefaultSignatureResult)result).Collect()); } else if (result is IBlockResult) { return(((IBlockResult)result).Collect()); } else if (result is byte[]) { return((byte[])result); } throw new InvalidOperationException("result is not byte[] or DefaultSignatureResult"); }
public PkiMessage(PkiHeader header, PkiBody body, DerBitString protection, CmpCertificate[] extraCerts) { this.header = header; this.body = body; this.protection = protection; if (extraCerts != null) { this.extraCerts = new DerSequence(extraCerts); } }
public ProtectedPkiMessage Build(IMacFactory factory) { IStreamCalculator calculator = factory.CreateCalculator(); FinalizeHeader((AlgorithmIdentifier)factory.AlgorithmDetails); PkiHeader header = hdrBuilBuilder.Build(); DerBitString protection = new DerBitString(CalculateSignature(calculator, header, body)); return(FinalizeMessage(header, protection)); }
public ProtectedPkiMessage Build(ISignatureFactory signatureFactory) { IStreamCalculator calculator = signatureFactory.CreateCalculator(); if (!(signatureFactory.AlgorithmDetails is AlgorithmIdentifier)) { throw new ArgumentException("AlgorithmDetails is not AlgorithmIdentifier"); } FinalizeHeader((AlgorithmIdentifier)signatureFactory.AlgorithmDetails); PkiHeader header = hdrBuilBuilder.Build(); DerBitString protection = new DerBitString(CalculateSignature(calculator, header, body)); return(FinalizeMessage(header, protection)); }
public ProtectedPkiMessage Build(IMacFactory factory) { if (null == body) { throw new InvalidOperationException("body must be set before building"); } IStreamCalculator calculator = factory.CreateCalculator(); FinalizeHeader((AlgorithmIdentifier)factory.AlgorithmDetails); PkiHeader header = hdrBuilBuilder.Build(); DerBitString protection = new DerBitString(CalculateSignature(calculator, header, body)); return(FinalizeMessage(header, protection)); }
private ProtectedPkiMessage FinalizeMessage(PkiHeader header, DerBitString protection) { if (extraCerts.Count > 0) { CmpCertificate[] cmpCertificates = new CmpCertificate[extraCerts.Count]; for (int i = 0; i < cmpCertificates.Length; i++) { byte[] cert = ((X509Certificate)extraCerts[i]).GetEncoded(); cmpCertificates[i] = CmpCertificate.GetInstance((Asn1Sequence.FromByteArray(cert))); } return(new ProtectedPkiMessage(new PkiMessage(header, body, protection, cmpCertificates))); } return(new ProtectedPkiMessage(new PkiMessage(header, body, protection))); }
private PkiMessage(Asn1Sequence seq) { header = PkiHeader.GetInstance(seq[0]); body = PkiBody.GetInstance(seq[1]); for (int i = 2; i < seq.Count; i++) { Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)seq[i].ToAsn1Object(); if (asn1TaggedObject.TagNo == 0) { protection = DerBitString.GetInstance(asn1TaggedObject, isExplicit: true); } else { extraCerts = Asn1Sequence.GetInstance(asn1TaggedObject, explicitly: true); } } }
private PkiMessage(Asn1Sequence seq) { header = PkiHeader.GetInstance(seq[0]); body = PkiBody.GetInstance(seq[1]); for (int pos = 2; pos < seq.Count; ++pos) { Asn1TaggedObject tObj = (Asn1TaggedObject)seq[pos].ToAsn1Object(); if (tObj.TagNo == 0) { protection = DerBitString.GetInstance(tObj, true); } else { extraCerts = Asn1Sequence.GetInstance(tObj, true); } } }
public virtual PkiHeader Build() { Asn1EncodableVector v = new Asn1EncodableVector(pvno, sender, recipient); AddOptional(v, 0, messageTime); AddOptional(v, 1, protectionAlg); AddOptional(v, 2, senderKID); AddOptional(v, 3, recipKID); AddOptional(v, 4, transactionID); AddOptional(v, 5, senderNonce); AddOptional(v, 6, recipNonce); AddOptional(v, 7, freeText); AddOptional(v, 8, generalInfo); messageTime = null; protectionAlg = null; senderKID = null; recipKID = null; transactionID = null; senderNonce = null; recipNonce = null; freeText = null; generalInfo = null; return(PkiHeader.GetInstance(new DerSequence(v))); }
public PkiMessage( PkiHeader header, PkiBody body) : this(header, body, null, null) { }
public ProtectedPart(PkiHeader header, PkiBody body) { this.header = header; this.body = body; }
private ProtectedPart(Asn1Sequence seq) { header = PkiHeader.GetInstance(seq[0]); body = PkiBody.GetInstance(seq[1]); }