title: Using Java to verify signature created in Golang
body: <p>I'm creating a signature in Go, for example:</p>
  
  <pre><code>//I'm reading a file with -----BEGIN RSA PRIVATE KEY-----
  privateKeyPem := strings.Replace(privateKeyString, `\n`, "\n", -1) //file has '/n' instead of break lines for dev purposes
  block, _ := pem.Decode([]byte(privateKeyPem))
  key, _ := x509.ParsePKCS1PrivateKey(block.Bytes)
  hashedString := sha256.Sum256([]byte(stringTosign))
  signature, err = rsa.SignPKCS1v15(rand.Reader, key, crypto2.SHA256, hashedString[:])
  signatureString := base64.StdEncoding.EncodeToString(signature)
  </code></pre>
  
  <p>Java program receives the variable signatureString and does:</p>
  
  <pre><code>byte[] keyBytes = Files.readAllBytes(Paths.get("./golangSignerPubKey.der"));
  X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
  KeyFactory kf = KeyFactory.getInstance("RSA");
  PublicKey publicKey =  kf.generatePublic(spec);
  Signature signature = Signature.getInstance("SHA256withRSA", "BC");
  signature.initVerify(publicKey);
  signature.update(stringUnsigned.getBytes());
  boolean signatureIsValid = signature.verify(Base64.getDecoder().decode(signatureString.getBytes()));
  </code></pre>
  
  <p>But the signatureIsValid boolean is always false, am I doing something wrong? </p>