2

Not sure if that is the best of titles but...

In my android app I'm trying to verify a signed string.

My method to do this works if I copy and paste the signedString and the Signature into my Django/Python method directly (I get these strings from my logcat).

But when I try to actually send that data to the server, it always comes up saying it is not verified.

I have tried .encode('ascii') and .encode('utf_8') [just blindly trying these things] and nothing has worked.

Any suggestions?

1 Answer 1

2

You should make the encoding and decoding explicit on both ends just to make sure. So, in your Android app, first encode the String into UTF-8 bytes using getBytes("UTF-8"). Compute the signature of this byte array. Then, I'd encode the resulting byte arrays (the message and the signature) into Base64 to get nice chunk of ASCII with no whitespace that will survive any encoding on the wire.

On the Python side, do the reverse. Base64-decode the message and the signature. Compute the signature for the message string and compare with the received signature. (Remember than in Python before 3.x, a "string" is really a byte array, and a "unicode" is what would be considered a String in Java.) Then decode the message byte array using message.decode('utf-8') to get what you started with on the Android side.

Sign up to request clarification or add additional context in comments.

2 Comments

Didn't have to decode on the python side but everything works great! thanks : )
@IamAlexAlright The last decode isn't really necessary if you're not working with internationalised strings. In which case you could've used ASCII for the message <-> bytes encoding step, but with UTF-8 you can be sure it won't choke on any string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.