Download V12 Database Engine
Transcript
on decrypt str set res = "" -- first clean up escape codes set str = cleanEscape (str) set keyLength = length (gEncryptKey) set strLength = length (str) repeat with i = 1 to strLength set keyIdx = i mod keyLength set res = res & numToChar ((charToNum (char i of str) - ¬ charToNum (char keyIdx of gEncryptKey) + 256) mod 256) end repeat return res end decrypt on cleanEscape str -- just replace every instance of 0101 by 01, and 0102 by 00 set res = "" set strLength = length (str) repeat with i = 1 to strLength if (charToNum (char i of str) = 1) then if (charToNum (char i + 1 of str) = 2) then set res = res & numToChar (0) else if (charToNum (char i + 1 of str) = 1) then set res = res & numToChar (1) end if set i = i + 1 else set res = res & char i of str end if end repeat return res end cleanEscape To use the above handlers, first assign the encryption key of your choice to the global variable gEncryptKey. Then, at startup, call initCrypt (e.g., on StartMovie). To store an encrypted string to a V12 table, call: mSetField(gT, "Account", encrypt(secretData) ) To retrieve an encrypted string from a V12 table, call: set x = decrypt (mGetField(gT, "Account", encrypt(secretData) ) You can further enhance the strength of your encryption by creating an additional field in your table for the encryption key — as opposed to using the same global gEncryptKey for all fields and records. Thus, each record would be encrypted with a different key, making it harder to hackers to crack your algorithm. If you want to encrypt dates, floats or integers, convert them to strings first. V12-DBE® for Macromedia Director® - User Manual ©Integration New Media, Inc. 1995-99 version 3.0 (99/07/27) page 157