0

I'm having trouble getting php's mcrypt function to encrypt text in a way that can be stored in my mysql database.

Here's an example of a query that doesn't work:

UPDATE mydatabase.clients SET firstname='\'å»”é¶Q' WHERE id_client=65

But if I change it to be:

UPDATE mydatabase.clients SET firstname='Test' WHERE id_client=65

Then it works. So it must be those crazy mcrypt characters throwing things off.

What do I do to my mysql database so it accepts those characters?

3 Answers 3

1

The output of a cipher is a string of bytes, not characters. You shouldn't store cipher text directly as text. Use a "binary" data type, or transform the byte string to text with something like Base-64.

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

Comments

0

Change the column type to binary instead, this may work.

Comments

0

Make sure you are escaping the encrypted string. It's an important part to doing this right!

I've been working with MySQL and Mcrypt and I store my encrypted data and initialization vectors as binary and I escape all of these strings before they get put in a query. Works like a charm.

Comments

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.