Written by

Question wx fg · Jul 10, 2017

How to encrypt column value in sql?

hi

   I want to update  some columns in one table like this:

    update table1 set col1=%SYSTEM.Encryption_AESCBCEncrypt(col1, 'key')

 

but the error is 

ERROR #5540: SQLCODE: -359 Message: User defined SQL Function '%SYSTEM.ENCRYPTION_AESCBCENCRYPT' does not exist

 

what's the corect syntax?  Thanks!

Comments

Michael Braam · Jul 18, 2017

You need to wrap it into a classmethod which is exposed as a stored procedure as in the example below:

Class DC.Utils [ Abstract ]
{
ClassMethod AESBCEncrypt(
pPlainText As %String,
pKey As %String) As %String [ SqlProc ]
{
return $system.Encryption.AESCBCEncrypt(pPlainText, pKey)
}
}

 Once you have done this, you can use something like:

update sample.person (Name) values (DC.Utils_AESBCEncrypt(name,'key'))
0