Encrypted Files

 

encryptFile <in_filename_string> <out_filename_string> <key_integer>

Creates an encrypted copy of the file named by <in_filename_string> using the integer supplied as a key, naming the encrypted file <out_filename_string>.

 

openEncryptedFile <filename_string> <key_integer>

Opens the encrypted file using the given integer key and returns a FileStream value that you can then do read calls on, exactly as you can on FileStreams returned from the openFile() function.

encryptFile() and openEncryptedFile() let you encrypt a text file with your own key and open an encrypted file via a key for reading. Among other things, you can use this to write and read an encrypted file containing a hardware lock ID for doing authorization-based piracy protection.

Here is some code that creates an encrypted lock ID file in some authorization process.

For example,

f = createFile "lock.tmp"

format "%" hardwareLockID to:f

close f

encryptFile "lock.tmp" "lock.dat" 5476557

deleteFile "lock.tmp"

The following code can be used to read and check the lock ID (obviously, all this is only safe if the creation and checking scripts are themselves encrypted):

For example,

f = openEncryptedFile "lock.dat" 5476557

id = readValue f

close f

if id != hardwareLockID then

(

message "Lock ID's don't match"

return 0

)