Example - sending a TSP request to a server
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();