title: Bouncy Castle C# prime256v1 ECDSA signature
body: <p>I'm trying to compute the ECDSA signature of some data in C# (within a Unity project, using Bouncy Castle) using an existing private key (the private key having been generated using <code>openssl ecparam -name prime256v1 -genkey -noout -out eckey.pem</code> in terminal on macOS).</p>
  <p>This is for the purpose of connecting to Apple's CloudKit as described under 'Authenticate Web Service Requests' <a href="https://developer.apple.com/library/archive/documentation/DataManagement/Conceptual/CloudKitWebServicesReference/SettingUpWebServices.html#//apple_ref/doc/uid/TP40015240-CH24-SW6" rel="nofollow noreferrer">here</a>.</p>
  <p>At the moment I'm trying with this, but the CreateKey fails with an IOException <code>extra data found after object</code>, thrown from Asn1Object.cs:24.</p>
  <pre><code>string privateKey = &quot;&lt;contents (within the BEGIN and END markers) of the privatekey.pem file I've previously generated&gt;&quot;;
  var key = PrivateKeyFactory.CreateKey(Encoding.UTF8.GetBytes(privateKey));
  
  var data = Encoding.UTF8.GetBytes(&quot;some data here&quot;);
  var signer = SignerUtilities.GetSigner(&quot;SHA256withECDSA&quot;);
  signer.Init(true, key);
  signer.BlockUpdate(data, 0, data.Length);
  var signature = signer.GenerateSignature();
  
  Debug.Log(signature);
  </code></pre>
  <p>I've tried keeping the newline characters in the private key string, as well as removing them - both give the same result.</p>
  <p>Any assistance in loading the key correctly would be awesome, and then secondly how to correctly call GetSigner to get the correct EDCSA signer to generate the signature I need (as I'm sure <code>SHA256withECDSA</code> is wrong, but I can't see in the source code what I should use).</p>
  <p><strong>Edit:
  I've tried using PemReader and been able to load the private key. I'm now just trying to work out how to use the correct signer.</strong></p>