title: How to retrieve the Signature hash algorithm friendly name using c# cryptography?
body: <p>The following function uses a certificate to sign and verify.</p>
  
  <pre><code>private static bool Sign_Verify(X509Certificate2 x509, byte[] random_data)
          {
              //
              // Local variable definitions
              //
              bool isVerified = false;
              byte[] buffer = Encoding.Default.GetBytes("Hello World ... !");
              byte[] signature_Data = null;
              byte[] signature_Hash = null;
              //
              // Retrieve the private key of the certificate selected.
              //
              RSACryptoServiceProvider privateKey
  
                                    = x509.PrivateKey as RSACryptoServiceProvider;
  
          if (null == privateKey)
          {
              Console.WriteLine("Invalid Private Key");
          } // if
          else
          {
              Console.WriteLine("Certificate has private key.");
          } // else
  
          HashAlgorithm hashAlgo = HashAlgorithm.Create("SHA256");
  
          byte[] hash = hashAlgo.ComputeHash(random_data);
  
          //
          // Perform signing using the private key
          try
          {
              signature_Hash = privateKey.SignHash(
                                                      hash,
                                                      CryptoConfig.MapNameToOID("SHA256"));
              if (null == signature_Hash)
              {
                  Console.WriteLine("Error: SignHash\n\n");
              } // if
              else
              {
                  Console.WriteLine("Signature_Hash generated......\n\n");
              } // else
          } // try
          catch (CryptographicException)
          {
              //e.StackTrace();
          } // catch
  
          //
          // Retrieve the public key of the certificate selected.
          //
          RSACryptoServiceProvider publicKey
  
                                      = x509.PublicKey.Key as RSACryptoServiceProvider;
          if (null == publicKey)
          {
              Console.WriteLine("Invalid Public Key");
          } // if
          else
          {
              Console.WriteLine("Certificate has public key.");
          } // else
  
  
           isVerified = publicKey.VerifyHash(
                                                  hash,
                                                  CryptoConfig.MapNameToOID("SHA256"),
                                                  signature_Hash);
          if (false == isVerified)
          {
              Console.WriteLine("Signature of Hash verification failed.");
          } // if
          else
          {
              Console.WriteLine("Signature of Hash verified successfully.");
          } // else
  
          return isVerified;
      } // Sign_Verify 
  </code></pre>
  
  <p>In the HashAlgorithm.Create("SHA256"); , we are hard coding the name of signature hash algorithm. How to get the name of the signature hash algorithm of the certificate instead of hard coding it?</p>