Time-Stamp Protocol (TSP)
[Hashing Home][Home]
This page will time stamp and verify that the data existed at the timestamp. Theory
|
Sample Code
[HttpPost] public ActionResult time(FormCollection form) { string inp = form["data"]; SHA1 sha1 = SHA1CryptoServiceProvider.Create(); byte[] hash = sha1.ComputeHash(Encoding.ASCII.GetBytes(inp)); TimeStampRequestGenerator reqGen = new TimeStampRequestGenerator(); // Dummy request TimeStampRequest request = reqGen.Generate( TspAlgorithms.Sha1, hash, 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(); TimeStampToken t =response.TimeStampToken; ViewData["res1"] = "Serial Number: "+t.TimeStampInfo.TstInfo.SerialNumber.ToString(); ViewData["res2"] = "Gen Time: "+t.TimeStampInfo.GenTime.ToString(); ViewData["res3"] = "Policy " + t.TimeStampInfo.Policy.ToString(); string obj = Global.ByteToString(t.TimeStampInfo.GetEncoded()); obj = addlinebreaks(obj,32,32); ViewData["res4"] = "Encoded timestamp: " +obj ; return PartialView("time_partial"); }