title: bouncycastle How to determine first byte (recovery ID) for ECDSA signatures
body: <p>I'm using BouncyCastle to sign transactions for the EOS blockchain. Similar to Bitcoin signatures, the signature needs to have a &quot;recovery ID&quot; as the 1st bytes. My code looks as follows:</p>
  <pre class="lang-cs prettyprint-override"><code>var curve = SecNamedCurves.GetByName(&quot;secp256r1&quot;);
  var domain = new ECDomainParameters(curve.Curve, curve.G, curve.N, curve.H);
  
  var p = new Org.BouncyCastle.Math.BigInteger(privateKey);
  
  var keyParameters = new ECPrivateKeyParameters(
                          new Org.BouncyCastle.Math.BigInteger(1,privateKey),
                          domain);
  
  ISigner signer = SignerUtilities.GetSigner(&quot;SHA-256withPLAIN-ECDSA&quot;);
  
  signer.Init(true, keyParameters);
  signer.BlockUpdate(message, 0, message.Length);
  var signature = signer.GenerateSignature();
  </code></pre>
  <p>This seems to work as expected but I'm unable to get the recovery ID.</p>
  <p>Here's an example of how another library does this.
  <a href="https://github.com/EOSIO/eosjs-ecc/blob/a806b93fbbccec8d38c0c02998d204ff2040a6ae/src/ecdsa.js#L199" rel="nofollow noreferrer">https://github.com/EOSIO/eosjs-ecc/blob/a806b93fbbccec8d38c0c02998d204ff2040a6ae/src/ecdsa.js#L199</a></p>
  <p>Can someone explain how I can do that same using BouncyCastle please?</p>
  <p>This was another post that seemed helpful, but wasn't specific to how to do this with BouncyCastle <a href="https://bitcoin.stackexchange.com/questions/83035/how-to-determine-first-byte-recovery-id-for-signatures-message-signing">https://bitcoin.stackexchange.com/questions/83035/how-to-determine-first-byte-recovery-id-for-signatures-message-signing</a></p>