databasepostgresqlperformancesecurityencryption

The most suitable way to store encrypted data in Postgres


I've got a byte array (about 100 bytes maximum) of data encrypted with AES/GCM. I wonder if you could help me choose the best data type for it. On my past project we were just using varchar2 in Oracle but now I'm doing the choice myself.

Should I use byte array or varchar or something else?

Which type is the most suitable in terms of security and performance?

Thank you!


Solution

  • If that is binary data, the bytea data type would be the best match.

    Using a string data type would only cause encoding problems, and you wouldn't be able to store zero bytes.