DecryptFile
Back to ListDescription: Decrypts a file on disk
FileMaker Prototype:
Set Variable [$res; ACF_Run("DecryptFile"; string_path; string_key)]
Category: ENCRYPTION
Function source:
/*
Decrypt a file on disk. Function asks for file,
and create a new file removing .encrypted as extention.
the function verifies that the filename has .encrypted in it.
*/
function DecryptFile (string path, string key)
string opath;
int x;
string content, decrypted;
if ( path == "") then
path = select_file ( "Select a encrypted file to decrypt");
end if
if ( path != "") then
if ( pos ( path, ".encrypted")>0) then
if ( key == "") then
key = "SablaBabla029c";
end if
x = open ( path, "r");
content = read ( x );
close (x);
decrypted = decrypt ( aes256cbc, key, content, binary);
opath = substitute (path, ".encrypted", "");
x = open ( opath, "w");
write ( x, decrypted ) ;
close (x);
// delete_file (path);
end if
end if
return "OK";
end
DecryptFile do a AES256 decryption on a file on disk, it produces a new file without the excrypted extention, with the original name.
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 = "...".
The function tests for .encrypted extention of the input path.
Example
Set Variable [$res; ACF_Run("DecryptFile"; "~/Desktop/MyPlainFile.docx.encrypted"; "MySecretKey")]
The file MyPlainFile.docx appears on the users desktop.
We have commented out the final "delete file", but this can be included after some testing.
Se also EncryptFile
