2 * build: gcc -o eet_data_file_cipher_decipher eet-data-file_cipher_decipher.c `pkg-config --cflags --libs eet eina`
16 const char *buffer = "Here is a string of data to save !";
17 const char *key = "This is a crypto key";
18 const char *key_bad = "This is another crypto key";
20 char *file = strdup("/tmp/eet_cipher_example_XXXXX");
27 if (!(file = tmpnam(file)))
30 stderr, "ERROR: could not create temporary file (%s).\n", file);
34 /* Crypt an eet file. */
35 ef = eet_open(file, EET_FILE_MODE_WRITE);
39 stderr, "ERROR: could not access file (%s).\n", file);
43 if (!eet_write_cipher(ef, "keys/tests", buffer, strlen(buffer) + 1, 0, key))
46 stderr, "ERROR: could not access file (%s).\n", file);
52 /* Decrypt an eet file. */
53 ef = eet_open(file, EET_FILE_MODE_READ);
57 stderr, "ERROR: could not access file (%s).\n", file);
61 test = eet_read_cipher(ef, "keys/tests", &size, key);
65 stderr, "ERROR: could decript contents on file %s, with key %s.\n",
70 if (size != (int)strlen(buffer) + 1)
73 stderr, "ERROR: something is wrong with the decripted data\n");
77 if (memcmp(test, buffer, strlen(buffer) + 1) != 0)
80 stderr, "ERROR: something is wrong with the decripted data\n");
86 /* Decrypt an eet file, now using our BAD key!! */
87 ef = eet_open(file, EET_FILE_MODE_READ);
91 stderr, "ERROR: could not access file (%s).\n", file);
95 test = eet_read_cipher(ef, "keys/tests", &size, key_bad);
97 if (size == (int)strlen(buffer) + 1)
98 if (memcmp(test, buffer, strlen(buffer) + 1) == 0)
101 stderr, "ERROR: something is wrong with the contents of %s, as"
102 " we accessed it with a different key and it decripted our"
103 " information right.\n", file);
110 if (unlink(file) != 0)
113 stderr, "ERROR: could not unlink file (%s).\n", file);