Encryption [examples]

Specify the default encryption key to be used when an encrypted table is accessed
SET ENCRYPTION
// Specify the default encryption key to be used when 
// an encrypted table is accessed 

encrypt table1 key "key_1,key_2,key_3"
encrypt table2 key "key_2,key_3,key_4"
set encryption to "key_1,key_2,key_3"
use table1
use table2<key_2,key_3,key_4>
set encryption to
use table1 encryption "key_1,key_2,key_3"
use table2<key_2,key_3,key_4>

Decrypt the specified table or tables
DECRYPT
decrypt accounts key "key1,key2,key3"
decrypt salaries key "<key_1,key_2,key_3>"
 
// decrypt all .dbf files in the directory
decrypt *.dbf key "key1,key2,key3"

Encrypt the specified table or tables
ENCRYPT
encrypt accounts key "key1,key2,key3"
encrypt salaries key "<key_1,key_2,key_3>"
 
// encrypt all .dbf files in the directory
encrypt *.dbf key "key1,key2,key3"

Return the MD5 cryptographic key for a character string
MD5
md5key = md5("Oeh987we")
? md5key
20aed6c51c904428ee6a60d3f460f0cb

https://www.lianja.com/doc/index.php/MD5()


Encode a string with MIME base64
BASE64_ENCODE
// Write encoded password to a file
m_pass=space(10)
@10,10 get m_pass
read
strtofile(base64_encode(m_pass),"password.txt")

https://www.lianja.com/doc/index.php/BASE64_ENCODE()


Decode a string encoded with MIME base64
BASE64_DECODE
// Check password against file
m_pass=space(10)
@10,10 get m_pass
read
if m_pass <> base64_decode(filetostr("password.txt"))
    // invalid password
    return
endif

https://www.lianja.com/doc/index.php/BASE64_DECODE()


Return the MD5 cryptographic key for a named file or files matching a skeleton
MD5FILE
md5key = md5file("*.dbf")                                                     
? md5key                                                                      
a867a1593181165651ed1e4330f451ba

https://www.lianja.com/doc/index.php/MD5FILE()


Return the SHA-1 cryptographic hash value for a character string
SHA1
? sha1("The quick brown fox jumps over the lazy dog")
2FD4E1C67A2D28FCED849EE1BB76E7391B93EB12

https://www.lianja.com/doc/index.php/SHA1()


Return the SHA-1 cryptographic hash value for one or more files
SHA1FILE
open database southwind
? sha1file("*.dbf")
DA39A3EE5E6B4B0D3255BFEF95601890AFD80709

https://www.lianja.com/doc/index.php/SHA1FILE()


Return the CRC32 checksum value for a character string
CRC32
? crc32("Lianja")

https://www.lianja.com/doc/index.php/CRC32()


Return the decrypted character string from a 3DES encrypted character value
DES3_DECRYPT
cEncrypted = des3_encrypt("LIANJA","abcdEFGH","ijklm123","45673$%^")
cDecrypted = des3_decrypt(cEncrypted,"abcdEFGH","ijklm123","45673$%^")

https://www.lianja.com/doc/index.php/DES3_DECRYPT()


Return the 3DES encrypted character value for a character string
DES3_ENCRYPT
cEncrypted = des3_encrypt("LIANJA","abcdEFGH","ijklm123","45673$%^")
cDecrypted = des3_decrypt(cEncrypted,"abcdEFGH","ijklm123","45673$%^")

https://www.lianja.com/doc/index.php/DES3_ENCRYPT()


// Encrypt individual tables
encrypt customers key "key_1,key_2,key_3"
encrypt employees key "<key_1,key_2,key_3>"
 
// Encrypt all .dbf files in the directory
encrypt *.dbf key "key_1,key_2,key_3"
// Encrypt individual tables
encrypt customers key "key_1,key_2,key_3"
encrypt shippers key "key_2,key_3,key_4"
// Specify a default encryption key
set encryption to "key_1,key_2,key_3"
// Open customers table using the default encryption key
use customers
// Specify shippers table's encryption key
use shippers<key_2,key_3,key_4>
// Disable the default encryption key
set encryption to
// Specify the individual encryption keys
use customers encryption "key_1,key_2,key_3"
use shippers<key_2,key_3,key_4>
// Decrypt individual tables
decrypt customers key "key_1,key_2,key_3"
decrypt employees key "<key_1,key_2,key_3>"
 
// Decrypt all .dbf files in the directory
decrypt *.dbf key "key_1,key_2,key_3"

Affected Commands

All of the following commands are affected when a table is encrypted:

Append from

append from – append records to the active table from another table

// The key must be specified for an encrypted source table
use mycustomers
append from customers encryption "key_1,key_2,key_3";
for country = "UK"

Copy file

copy file – copy a file

// The key file must also be copied for an encrypted source table
// as the target table will be encrypted
encrypt customers key "key_1,key_2,key_3"
copy file customers.dbf to newcustomers.dbf
copy file customers.dkf to newcustomers.dkf
use newcustomers encryption "key_1,key_2,key_3"

Copy structure

copy structure – copy a table’s structure to a new table

// The key file is automatically copied for an encrypted source table
// and the target table encrypted
encrypt customers key "key_1,key_2,key_3"
use customers encryption "key_1,key_2,key_3"
copy structure to blankcust
use blankcust encryption "key_1,key_2,key_3"

Copy

copy – copy a table

// By default, the key file is automatically copied for an encrypted
// source table and the target table encrypted with the same key
encrypt customers key "key_1,key_2,key_3"
use customers encryption "key_1,key_2,key_3"
copy to newcustomers
use newcustomers encryption "key_1,key_2,key_3"
// You can also create a copy with a different key
encrypt customers key "key_1,key_2,key_3"
use customers encryption "key_1,key_2,key_3"
copy to newcustomers encrypt "newkey_1,newkey_2,newkey_3"
use newcustomers encryption "newkey_1,newkey_2,newkey_3"
// Or create a decrypted copy
encrypt customers key "key_1,key_2,key_3";
use customers encryption "key_1,key_2,key_3"
copy to newcustomers decrypt
use newcustomers
// You can also create an encrypted copy of a non-encrypted source table
use orders
copy to encorders encrypt "newkey_1,newkey_2,newkey_3"
use encorders encryption "newkey_1,newkey_2,newkey_3"

Use

use – open a table

// The three part key must be specified to open an
// encrypted table.  All of the following are valid.
// 1. Specifying a default encryption key before opening the table
set encryption to "key_1,key_2,key_3"
use customers
// 2. Appending the key to the filename
use customers<key_1,key_2,key_3>
// 3. Using the ENCRYPTION clause, optionally specifying angled brackets
use customers encryption "key_1,key_2,key_3"
use customers encryption "<key_1,key_2,key_3>"

Insert

SQL insert – add a row to a table

// The three part key can be specified using a
// default encryption key before opening the table
open database southwind
set encryption to "key_1,key_2,key_3"
insert into customers;
  (customerid, companyname);
  values ("LIANJ","Lianja Inc")
// Or by appending the key to the filename
open database southwind
insert into customers<key_1,key_2,key_3>;
  (customerid, companyname);
  values ("LIANJ","Lianja Inc")

Select

SQL select – return data from a table or tables

// The three part key can be specified using a
// default encryption key before opening the table
open database southwind
set encryption to "key_1,key_2,key_3"
select * from customers
// Or by appending the key to the filename
open database southwind
select * from customers<key_1,key_2,key_3>

Update

SQL update – update data in a table

// The three part key can be specified using a
// default encryption key before opening the table
open database southwind
set encryption to "key_1,key_2,key_3"
update customers;
  set companyname="Lianja Inc.";
  where customerid="LIANJ"
// Or by appending the key to the filename
open database southwind
update customers<key_1,key_2,key_3>;
  set companyname="Lianja Inc.";
  where customerid="LIANJ"

https://www.lianja.com/doc/index.php/Encryption


Advertisements