3

I want to encrypt text using AES in mysql, but I have a small problem, because you need to use varbinary to store these.

Some of my datatypes are varchar and yes I can probably work out the length of my varbinary for these. However for my address fields I use the TEXT datatype, as we have Chinese addresses stored and these can be very long. I use the TEXT datatype because you do not need to specify a length in mysql.

The problem is that with varbinary you need to specify a length, and I don't really know the length because the addresses can be of any length.

Is there some kind of binary datatype I can use for AES where I don't have to specify the length of the data?

Thomas Williams
  • 1,528
  • 1
  • 18
  • 37
  • 1
    You're after `blob` or binary long object. If `varbinary` is charset-less equivalent to `varchar`, then that's what `blob` is to `text`. – Mjh Jul 07 '16 at 15:07
  • Thank you. If you leave your comment as an answer I can vote you up – Thomas Williams Jul 07 '16 at 15:25
  • 1
    @Mjh That's Binary *Large* Object if I'm not mistaken. There is also a [`MEDIUMBLOB` and `LARGEBLOB`](http://stackoverflow.com/a/5775601/589259) so calling it a Binary *Long* Object may confuse readers. Otherwise the hint is of course OK. – Maarten Bodewes Jul 07 '16 at 20:01
  • @MaartenBodewes - thanks for the correction, added to the answer! – Mjh Jul 12 '16 at 10:02

1 Answers1

5

As per comments - you require BLOB data type, which is short for Binary Large Object (thanks Maarten Bodewes for clarification).

A BLOB data type won't store character set with the information and is equivalent to TEXT type, without a charset. As mentioned in the comments, there are other types such as MEDIUMBLOB, TINYBLOB, LARGEBLOB, they are all covered on MySQL's manual page.

Mjh
  • 2,904
  • 1
  • 17
  • 16