kylef / JSONWebToken.swift

Swift implementation of JSON Web Token (JWT).
http://jwt.io
BSD 2-Clause "Simplified" License
763 stars 225 forks source link

Invalid signature against Java JWT implementation #115

Closed mejmo closed 6 years ago

mejmo commented 6 years ago

We are using the library but it is not possible to connect to JWT enabled services because they need to have secret base64 encoded. If we encode the password at first before pushing to the library, it is still saying that the generated JWT token is invalid.

So basically... the token generated in Swift works when the signature is generated in JWT.io with secret base64 encoded, so the signature is re-generated. Such token works. How can I let the library to encode the password for me? Thanks

image

baikal23 commented 6 years ago

We are having the same problem. Any workarounds or solutions would be much appreciated

mejmo commented 6 years ago

We found the issue - thing is, iOS needs the key in base64 encoded form. We were inserting the value in Java as following: String.getBytes() and not decodeBase64(String).getBytes(). You have to check that you are providing the secret in correct form at each place. We had just two places (iOS and Java) and using the key differently (secret decoded from base64 and on the other place not). Hope this helps.

baikal23 commented 6 years ago

Thanks for the info - We will give it a try

On Fri, Sep 28, 2018 at 7:46 AM Martin Formanko notifications@github.com wrote:

We found the issue - thing is, iOS needs the key in base64 encoded form. We were inserting the value in Java as following: String.getBytes() and not decodeBase64(String).getBytes(). You have to check that you are providing the secret in correct form at each place. We had just two places (iOS and Java) and using the key differently (secret decoded from base64 and on the other place not). Hope this helps.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kylef/JSONWebToken.swift/issues/115#issuecomment-425410373, or mute the thread https://github.com/notifications/unsubscribe-auth/Aopp_Wb7Pxc5G4P-ELDgBdtm41HfnToUks5ufgwFgaJpZM4V8qRO .

kylef commented 6 years ago

You can use the base64Encoded initialiser for Data: https://developer.apple.com/documentation/foundation/nsdata/1410081-init