This built-in predicate can encrypt and decrypt atoms. The first parameter is the atom to encrypt. The second argument is the encrypted atom, this atom is encoded with the base64 algorithm to produce a readable result after encryption. The last parameter is the key to use for encryption.
To decrypt an atom the first argument must be a variable and an encrypted atom must be supplied as the second argument.
The blowfish encryption algorithm is used to encrypt the atoms, 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.
see also: atom_base64/2 atom_codes/2 atom_compress/2 atom_concat/3 atom_final_md5/1 atom_integers/2 atom_length/2 atom_reset_md5/0 atom_update_md5/1 char_code/2 number_chars/2 number_codes/2 number_integers/2 sub_atom/5
| Examples | |
| atom_encrypt('testatom', A, 'key2_key_'). | succeeds and 'testatom' is encrypted, the result is unified
with variable A, A = 'adrHOu+sKlI=' |
| atom_encrypt(A, 'adrHOu+sKlI=', 'key2_key_'). | succeeds, the string 'adrHOu+sKlI=' is decrypted and the
result is unified with variable A, A = 'testatom' |
| atom_encrypt(another, 'adrHOu+sKlI=', 'key2_key_'). | fails, the atom 'another' is encrypted and the result is unified with 'adrHOu+sKlI=', this results in a mismatch |
| Exceptions | |
| The atom to encrypt and the encrypted atom are both variables | an instantiation_error exception is thrown |
| The third argument is a variable | an instantiation_error 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 |
| The atom to decrypt is not a correct base64 atom | an evaluation_error(decode_base64, Atom64) exception is thrown |