title: Signing data in JAVA with secp256k1 and verifying in c++
body: <p>I want to sign data in Java and then veify it in c++. When I sign the data in c++ with bitcoin-core/secp256k1 library and then verify it in c++ it works flawlessly. But when I sign it in Java and then transfer it to c++ it does not work anymore.</p>
  <pre><code>        secp256k1_context *ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
  
          secp256k1_pubkey pubkey;
          secp256k1_ecdsa_signature sig;
  
          signature_len = 71;
          // I paste in the generated signature from java
          const char* signature2 = &quot;3045022100C5C52074B7F86130D52FC6286D20E95D974D2A9457B8F39223FA571CA1419B5602203B5DA5922770EE472A2A6235B2FC07C1125763DC4C896A6561D4FD959FAA4C7D&quot;;
          char signature3[72];
          hex2bin(signature2, signature3);
          memcpy(signature, signature3, signature_len);
          
          // I paste in the generated public key from java
          const char* pub_key2 = &quot;0300F447B363996717EB807D950BC8C35C648F1AD27E98AD9E23487F4A4E7EEA2F&quot;;
          char pub_key3[33];
          hex2bin(pub_key2, pub_key3);
          memcpy(public_key, pub_key3, 33);
          
          std::string data = Vendor::sha256(&quot;BANANA&quot;);
          memcpy(hash, data.c_str(), 32);
  
          if (secp256k1_ec_pubkey_parse(ctx, &amp;pubkey, public_key, 33) == 0) {
              LOG_WNL(&quot;Error parsing public key!&quot;);
          }
  
          if (secp256k1_ecdsa_signature_parse_der(ctx, &amp;sig, signature, signature_len) == 0) {
              LOG_WNL(&quot;Error parsing signature!&quot;);
          }
  
          int res = secp256k1_ecdsa_verify(ctx, &amp;sig, hash, &amp;pubkey);
  
  
          return res == 1;
  </code></pre>
  <p>Java code:</p>
  <pre><code>            Signature dsa = Signature.getInstance(&quot;SHA256withECDSA&quot;);
  
              dsa.initSign(privateKey);
  
              String str = &quot;BANANA&quot;;
  
              Signature ecdsaSign = Signature.getInstance(&quot;SHA256withECDSA&quot;);
              ecdsaSign.initSign(privateKey);
              ecdsaSign.update(str.getBytes(&quot;ASCII&quot;));
  
              byte[] signature = ecdsaSign.sign();
              String sig = getHex(signature);
  
              return sig;
  </code></pre>
  <p>I would greatly appriciate an answer!</p>