title: Check signature for x509 certificate
body: <p>I have:</p>
  
  <ol>
  <li>x509 certificate (Base64);</li>
  <li>String data;</li>
  <li>Signature of string data (Base64).</li>
  </ol>
  
  <p>Is it possible to check signature?</p>
  
  <p>My code:</p>
  
  <pre><code>  bool valid = false;
  
    var signature = Convert.FromBase64String(base64Signature);
    var data = Encoding.UTF8.GetBytes(stringData);
  
    var x509 = new X509Certificate2(Convert.FromBase64String(certificate));
    var dsa = x509.PublicKey.Key as DSACryptoServiceProvider;
    if (dsa!=null)
      valid = dsa.VerifySignature(data, signature);
    else {
      var rsa = x509.PublicKey.Key as RSACryptoServiceProvider;
      if (rsa!=null)
        valid = rsa.VerifyHash(data, ???, signature);
    }
  </code></pre>
  
  <p>I don't know what I should use instead of ???. It is possible to get hash algorithm from certificate?</p>