0

In Postgres, I am using:

encrypt('text', 'mykey', 'aes')

https://www.postgresql.org/docs/8.3/pgcrypto.html - F.20.4. Raw encryption functions

I assume this is done using the defaults of AES-128 algorithm, CBC mode.

It appears to be stored as BINARY (16 bytes) in the database and comes back as a base64? encoded string when I request the column on the server with my ORM.

In Node.js, assuming I have 'mykey', how do I convert this value back to its plaintext using crypto or crypto-js libraries?

atkayla
  • 8,143
  • 17
  • 72
  • 132

1 Answers1

0

Could you use PostgreSQL's Pgp_sym_encrypt() instead, and then use it with https://www.npmjs.com/package/openpgp to decode? PostgreSQL's raw encryption functions are not really suitable for compatible use with external systems (and really, not suitable for use at all)

jjanes
  • 37,812
  • 5
  • 27
  • 34
  • true. pgp_sym_encrypt() is preferred. PostgreSQL's raw encryption functions lack of clear documentation. I left the details in my comments in https://stackoverflow.com/a/63095117/709065, hopefully it helps save time for other folks. – lovelywib Jul 26 '20 at 01:11