0

I am not sure what type of coded hash I am getting back from a postgres database that when queried shows instead a different code.

The question is...

how to convert this hash (as it is returned from Rails):

\x158\x06\xDB\xCD\x13M\xDE\xE6\x9A\x8CR\x04\xE3\x8A\xC8\x04H\xF6#B\xF8\xC2<\xFEK~\xDF

into this (as it shows inside the postgres database):

\x153806dbcd134ddee69a8c5204e38ac80448f62342f8c23cfe4b7edf

1 Answer 1

1

The first hash (as you say, coming from Rails) is a byte array, in which any printable character is left as is instead of being converted to hex: \x158 is really two characters: '\x15' and '\x38' ('8').

In the Postgres table, that byte array is the same, but the format is to hexlify the whole thing.

So:

\x158\x06\xDB\xCD\x13M... is really \x15,8,\x06,\xDB,\xCD,\x13,M
-- becomes
\x153806dbcd134d... ('8':\x38, 'M':\x4d)
Sign up to request clarification or add additional context in comments.

3 Comments

is there a way to hexify a byte array in Rails?
possibly, by adapting this.
for future reference this helped me

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.