Explore Courses Blog Tutorials Interview Questions
0 votes
in GCP by (19.7k points)
recategorized by

The following exception has started occurring on every API request to my Google Cloud Endpoint from my Android app: verifyToken: verifyToken: Signature length not correct: got 256 but was expecting 128

The call still works perfectly from my javascript web clients. I have changed nothing on the server-side code or client code.

Has anything changed with the service recently that might make this occur?

UPDATE: The first occurrence of this appears to have been at 11:17:07 UTC

UPDATE: Things that don't work include generating a new Client ID for android & updating to App Engine SDK 1.9.22


1 Answer

+1 vote
by (62.9k points)
selected by
Best answer

The following are the causes of it:

RSA has variable length signatures, depending on the key size.

Google updated the key pairs it uses for signing, and now one of the key pairs generates a different length signature from the other[] signature) throws an exception if a signature of the wrong length is passed (instead of returning false which is normally done when a signature does not match the key)

For me the solution was to wrap the verify call (try...catch), and return false instead. You could also do an early check on the public key yourself, checking if the length of the signature matches the length of the public key modulus.

If you use a library to check the signature, make sure you use the latest version.

Looking at the example code on, you would have to change this:

GoogleIdToken token = GoogleIdToken.parse(mJFactory, tokenString);


JsonWebSignature jws = JsonWebSignature.parser(mJFactory).setPayloadClass(Payload.class).parse(tokenString);

GoogleIdToken token = new GoogleIdToken(jws.getHeader(), (Payload) jws.getPayload(), jws.getSignatureBytes(), jws.getSignedContentBytes()) {

   public boolean verify(GoogleIdTokenVerifier verifier)

  throws GeneralSecurityException, IOException {

       try {

           return verifier.verify(this);

       } catch ( e) {

           return false;




 I, unfortunately, don't have an exact setup to test this.

For those using Google Cloud Endpoint, like the question states, I think there was very little you could do except wait until Google fixes it. Luckily it's fixed now. 

Browse Categories