Search code examples
c#bouncycastle

How do I get the signature in a TimeStampToken (Bouncy Castle)


From RFC 3852 (and RFC 3161) I understand that the signature value is stored as an attribute of the SignerInfo type of the TimestampToken (which is a Signed Data content type).

How can I get that signature value from a TimeStampToken instance of Bouncy Castle (in C#)?


Solution

  • I was able to get the signature using this:

    CmsSignedData tsTokenCms = timestampToken.ToCmsSignedData();
    SignerInformationStore signerInfoStore = tsTokenCms.GetSignerInfos();
    SignerInformation signerInfo = signerInfoStore.GetFirstSigner(timestampToken.SignerID);
    byte[] signatureBytes = signerInfo.GetSignature();
    string signatureString = BitConverter.ToString(signatureBytes);
    Console.WriteLine("Signature is: " + signatureString);