Xbasic

a5_encrypt_table_field Function

Syntax

P result = a5_encrypt_table_field(C connectionString, C tableName, C fieldName, C key, C mode)

Arguments

connectionStringCharacter

A database connection string.

tableNameCharacter

The table name.

fieldNameCharacter

The field name. The field must be a character field in the table.

keyCharacter

The encryption key. If mode is set to encrypt, the encrypted values in the field will have a prefix of ENCRYPTED: if the key is prefixed with prefix:. e.g. prefix:my_encryption_key

modeCharacter

The mode. Can be encrypt or decrypt.

Returns

resultPointer

Returns object with these properties:

errorLogical

.t. if an error occurred. Otherwise .f..

errorTextCharacter

Description of error, if an error occurred.

countErrorsNumeric

The number of errors that occurred.

countUpdateNumeric

The number of records that were updated.

Description

Encrypts or decrypts data stored in a table field.

Discussion

The a5_encrypt_table_field() function can be used to encrypt or decrypt data in a field for every record in a SQL table. Encrypted data takes up more space than decrypted data. Make sure that your database schema specifies fields that are sufficiently large to hold the encrypted data values.

dim cs as C = "::Name::AADemo-Northwind"
dim tablename as C = "Customers"
dim fieldname as C = "Address"
dim key as C = "example_key"
dim result as P

' Encrypt fields:
result = a5_encrypt_table_field(cs, tablename, fieldname, key, "encrypt")
if (result.error == .t.) then
    ' An error occurred
end if

' Decrypt fields:
result = a5_encrypt_table_field(cs, tablename, fieldname, key, "decrypt")
if (result.error == .t.) then
    ' An error occurred
end if

' Encrypt fields with a prefix:
result = a5_encrypt_table_field(cs, tablename, fieldname, "prefix:" + key, "encrypt")
if (result.error == .t.) then
    ' An error occurred
end if

' Decrypt fields with a prefix:
result = a5_encrypt_table_field(cs, tablename, fieldname, "prefix:" + key, "decrypt")
if (result.error == .t.) then
    ' An error occurred
end if

Videos

Encrypting/decrypting existing data

In this video, we show how the a5_encrypt_table_field() function can be used to encrypt or decrypt existing data in a field in a SQL table.

2020-08-14

See Also