EncryptFile
Back to ListDescription: Encrypt a file on disk
FileMaker Prototype:
Set Variable [$res; ACF_Run("EncryptFile"; string_path; string_key)]
Category: ENCRYPTION
Function source:
/*
Encrypt a file on disk. Function asks for file if not given in parameter path,
and create a new file with .encrypted as extention.
*/
function EncryptFile (string path, string key)
string opath;
int x;
string content, encrypted;
if ( path == "") then
path = select_file ( "Select a file to encrypt");
end if
if ( path != "") then
if ( key == "") then
key = "SablaBabla029c";
end if
x = open ( path, "r");
content = read ( x );
close (x);
encrypted = encrypt ( aes256cbc, key, content, binary);
opath = path + ".encrypted";
x = open ( opath, "w");
write ( x, encrypted ) ;
close (x);
// delete_file (path);
end if
return "OK";
end
EncryptFile do a AES256 encryption on a file on disk, it produces a new encrypted file with the same name, and extention .encrypted
If no filename is given, the user is asked to select a file. If no key is given, a default key is used (that should be changed when you copy this function). See the line `key = "...".
Example
Set Variable [$res; ACF_Run("EncryptFile"; "~/Desktop/MyPlainFile.docx"; "MySecretKey")]
The file MyPlainFile.docx.encrypted appears on the users desktop.
We have commented out the final "delete file", but this can be included after some testing.
