mardi 29 août 2017

sending Sha256 hash as a URL param as signature for Rails request data

I've noticed that when i send a url like this:

http://localhost:3000/register/register_user/?sig=zaQ/876CwJMEEmrJqAOYHyEKBXy2s03NDmk+3FsXPr4=

what comes through when I use it to compare to the expected result using params[:sig] in the controller is this:

zaQ/876CwJMEEmrJqAOYHyEKBXy2s03NDmk 3FsXPr4=

For some reason the '+' sign that was in the url at the 9th character from the end of the string has been converted to a space.

Not sure why that happens, whether it only happens with + signs or what.

The result returned by Digest::SHA256.base64digest(data) has this plus sign so my validation of the signature is failing.

What's the best way to fix this? Will it suffice in the general case just to convert '+' signs into spaces before the comparison or is the re some less ugly way to address?

Aucun commentaire:

Enregistrer un commentaire