This built-in predicate attempts to encrypt a file, the file to decrypt is the first argument. The second argument is the key to use for encrypting the file. The last argument determines how the encryption key is stored and if the user that decrypts the file may store the key or must always enter the key.
The blowfish encryption algorithm is used to encrypt the files, a key size of 128 bits is used to encrypt the data. This key is generated by using the supplied password as input to initialize the encryption key. Because a good password is required Trinc-Prolog checks the entered passwords. The password rules are:
| Password examples | |
| test2_ | this password is too short |
| test2test | there is no symbolic or special character in the password |
| test2_test | this is a correct password |
The blowfish encryption algorithm is free to use, there are no patents restraining its use and also no export restrictions, it was introduced by Bruce Schneier in 1994. For more information about the blowfish encryption algorithm visit the website of Counterpane; www.counterpane.com.
| To protect the contents of encrypted modules it is not possible to use the clause/2 predicate for these modules. |
The text editor can also encrypt and decrypt files, for more information see: text editor.
The first parameter of the encrypt/2 save-option determines how the encryption password is managed by the person that will decrypt the file. The three available options are:
Trinc-Prolog can detect if the entered password was correct, it does that by calculating an MD5 digest for the original data being encrypted and comparing it with the MD5 digest calculated while decrypting. Incorrect passwords are never stored. The MD5 digest algorithm is described in rfc1321.
see also: app_dir/1 base64_decode_file/2 base64_encode_file/2 compress_file/2 copy_file/2 current_dir/1 decompress_file/1 decompress_file/2 decrypt_file/3 delete_file/1 exists_dir/1 exists_file/1 info_file/2 make_dir/1 md5_file/2 next_file/2 next_file/3 next_dir/2 remove_dir/1 rename_file/2 set_current_dir/1 split_fn/2 unlink_file/1 wipe_file/1
| Examples | |
| encrypt_file('c:\\temp\\doc.txt', 'test2_test', store_key) | the file 'doc.txt' is decrypted with the key 'test2_test' and the key is stored inside the file |
| Exceptions | |
| The argument is an empty variable | an instantiation_error exception is thrown |
| The argument Arg is not an atom enclosed by single or double quotes | a type_error(atom_singlequotes, Arg) exception is thrown |
| The File to decrypt cannot be opened for reading | an existence_error(file, File) exception is thrown |
| The encrypt Option is an empty variable | an instantiation_error exception is thrown |
| The encrypt Option is not a atom | a type_error(atom, Option) exception is thrown |
| The encrypt Option is not one of the three valid options | a domain_error(encrypt_option, Option) exception is thrown |
| The decryption Key is a weak key | an evaluation_error(weak_encryption_key, Key) exception is thrown |
| The Key used for decrypting is invalid | an evaluation_error(incorrect_encryption_key, Key) exception is thrown |