mirrored from https://www.bouncycastle.org/repositories/bc-csharp
-
Notifications
You must be signed in to change notification settings - Fork 562
TSP Request Example
dghgit edited this page Aug 2, 2020
·
1 revision
Here is a basic example of how to use the classes in Org.BouncyCastle.Tsp
to send a TSP request to a server and collect the response:
TimeStampRequestGenerator reqGen = new TimeStampRequestGenerator();
// Dummy request
TimeStampRequest request = reqGen.Generate(
TspAlgorithms.Sha1, new byte[20], BigInteger.ValueOf(100));
byte[] reqData = request.GetEncoded();
HttpWebRequest httpReq = (HttpWebRequest) WebRequest.Create("http://www.cryptopro.ru/tsp/tsp.srf");
httpReq.Method = "POST";
httpReq.ContentType = "application/timestamp-query";
httpReq.ContentLength = reqData.Length;
// Write the request content
Stream reqStream = httpReq.GetRequestStream();
reqStream.Write(reqData, 0, reqData.Length);
reqStream.Close();
HttpWebResponse httpResp = (HttpWebResponse) httpReq.GetResponse();
// Read the response
Stream respStream = new BufferedStream(httpResp.GetResponseStream());
TimeStampResponse response = new TimeStampResponse(respStream);
respStream.Close();