title: .NET Core - How to verfiy a ECDSA signature with named curve
body: <p>I try to verfiy a signature with the named curve <code>secP256k1</code> and a public key in a byte array. I don't know how to add the public key to my <code>ECDsaCng</code> object. The hash of the data is a SHA256 hash.</p>
  <pre><code>static byte[] publicKey = new byte[] {
      0x04, 0xD3, ..., 0x20
  };
  
  public static bool VerifySignature(byte[] hash, byte[] signature)
  {
      using (ECDsaCng dsa = new ECDsaCng(ECCurve.CreateFromFriendlyName(&quot;secP256k1&quot;)))
      {
          // How to add the public key?
  
          bool result = dsa.VerifyHash(hash, signature);
  
          return result;
      }
  }
  </code></pre>
  <p>I tried to use <code>ImportSubjectPublicKeyInfo</code>, but I get the exception <strong>&quot;ASN1 corrupted data&quot;</strong></p>
  <pre><code>public static bool VerifySignature(byte[] hash, byte[] signature)
  {
      using (ECDsaCng dsa = new ECDsaCng(ECCurve.CreateFromFriendlyName(&quot;secP256k1&quot;)))
      {
          int bytesRead;
  
          dsa.ImportSubjectPublicKeyInfo(publicKey, out bytesRead);
  
          bool result = dsa.VerifyHash(hash, signature);
  
          return result;
      }
  }
  </code></pre>
  <p>I hope anyone have an idea to solve the problem or could show me a different way.</p>