title: Signing data with private key in c#
body: <p>I need to sign some data with one private key using Algorithm SHA1RSA ,Rsa Key length 2048 with 64 base encoding.My code is like this</p>
  <pre class="lang-cs prettyprint-override"><code>string sPayload = &quot;&quot;;
  HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(&quot;URI&quot;);
  httpWebRequest.ContentType = &quot;application/json; charset=utf-8&quot;;
  httpWebRequest.Method = WebRequestMethods.Http.Post;
  
  using (StreamWriter streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
  {
      sPayload = &quot;{\&quot;id\&quot;:\&quot;14123213213\&quot;,&quot; +
                  &quot;\&quot;uid\&quot;:\&quot;teller\&quot;,&quot; +
                  &quot;\&quot;pwd\&quot;:\&quot;abc123\&quot;,&quot; +
                  &quot;\&quot;apiKey\&quot;:\&quot;2343243\&quot;,&quot; +
                  &quot;\&quot;agentRefNo\&quot;:\&quot;234324324\&quot;}&quot;;
  
      httpWebRequest.Headers.Add(&quot;SIGNATURE&quot;, Convert.ToBase64String(new System.Security.Cryptography.SHA1CryptoServiceProvider().ComputeHash(Encoding.ASCII.GetBytes(sPayload))));
      
      streamWriter.Write(sPayload);
      streamWriter.Flush();
      streamWriter.Close();
  }
  
  System.Net.ServicePointManager.Expect100Continue = false;
  
  HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
  
  using (StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream()))
  {
      string result = streamReader.ReadToEnd();
  }
  </code></pre>
  <p>In the Header name Signature i need to pass the signed data(sPayload) using the private key.But using above code an error is getting  as &quot;invalid signature&quot; from  third party and i'am not sure whether the Encryption part is correct or not.</p>
  <pre class="lang-cs prettyprint-override"><code>httpWebRequest.Headers.Add(&quot;SIGNATURE&quot;, Convert.ToBase64String(new System.Security.Cryptography.SHA1CryptoServiceProvider().ComputeHash(Encoding.ASCII.GetBytes(sPayload))));
  </code></pre>
  <p>Third party had provide one certificate(cert,sha1) and key.should i refer that to the code?</p>