title: RSA java signature verification failed
body: <p>this might be a possible duplicate of:
  <a href="https://stackoverflow.com/questions/27053117/java-signature-verify-results-in-signatureexception-signature-encoding-error-ca">Java Signature.verify results in SignatureException: Signature encoding error Caused by IOException: Sequence tag error</a>
  , but the answer did not answer my question.</p>
  
  <p>Have this code:</p>
  
  <pre><code>String RSA_CIPHER_ALGORITHM = "RSA/ECB/PKCS1Padding";
  String RSA_KEY_FACTORY_ALGORITHM = "RSA";
  String RSA_SIGNATURE_ALGORITHM = "SHA512withRSA";
  
  KeyFactory keyFactory = KeyFactory.getInstance(RSA_KEY_FACTORY_ALGORITHM);
  RSAPublicKey key = (RSAPublicKey)keyFactory.generatePublic(pubKeySpec);
  
  Signature signature = Signature.getInstance(RSA_SIGNATURE_ALGORITHM);
  signature.initVerify(key);
  signature.update(data);
  </code></pre>
  
  <p>Have this error:</p>
  
  <pre><code>java.security.SignatureException: Signature encoding error
  at sun.security.rsa.RSASignature.engineVerify(RSASignature.java:204)
  at java.security.Signature$Delegate.engineVerify(Signature.java:1219)
  at java.security.Signature.verify(Signature.java:652)
  </code></pre>
  
  <p>...</p>
  
  <pre><code>Caused by: java.io.IOException: Sequence tag error
  at sun.security.util.DerInputStream.getSequence(DerInputStream.java:297)
  at sun.security.rsa.RSASignature.decodeSignature(RSASignature.java:229)
  at sun.security.rsa.RSASignature.engineVerify(RSASignature.java:195)
  ... 45 common frames omitted
  </code></pre>