encrypted column - with ZENDB

2 posts by 2 authors in: Forums > CMS Builder
Last Post: August 26   (RSS)

Hi Jeff, 

We don't have a built-in function for that yet, but you could try something like this: 

function getDecryptColumnSql($col) {
  static $key = null;
  $key ??= mysql_escape(settings('mysql.columnEncryptionKey'));
  $sql = "AES_DECRYPT(`$col`, UNHEX(SHA2('$key',512))) as '$col'";
  return DB::rawSql($sql);
}

$result = DB::query("SELECT num, :decryptedToken FROM ::myTable", [
  ':decryptedToken' => getDecryptColumnSql('token'),
]);

Let me know how that goes or any questions.

Thanks!

Dave Edis - Senior Developer
interactivetools.com