title: Encrypt / Decrypt in C# using Certificate
body: <p>I'm having trouble finding a good example in encrypting / decrypting strings in C# <em>using a certificate</em>. I was able to find and implement an example of <strong>signing</strong> and validating a signature, as shown below. Could someone point me to an easy, similar example for encryption?</p>
  
  <pre><code>private static string Sign(RSACryptoServiceProvider privateKey, string content)
  {
      SHA1Managed sha1 = new SHA1Managed();
      UnicodeEncoding  encoding = new UnicodeEncoding ();
      byte[] data = encoding.GetBytes(content);
      byte[] hash = sha1.ComputeHash(data);
  
      // Sign the hash
      var signature = privateKey.SignHash(hash, CryptoConfig.MapNameToOID("SHA1"));
      return Convert.ToBase64String(signature);
  }
  
  public static bool Verify(RSACryptoServiceProvider publicKey, string content, string hashString)
  {
      SHA1Managed sha1 = new SHA1Managed();
      UnicodeEncoding  encoding = new UnicodeEncoding ();
      byte[] data = encoding.GetBytes(content);
      byte[] hash = sha1.ComputeHash(data);
      return publicKey.VerifyHash(hash, CryptoConfig.MapNameToOID("SHA1"), Convert.FromBase64String(hashString));
  }
  </code></pre>