Aes_encrypt
Hello! I know this entry too old, but it was very useful to encrypt name and lastname fileds in mysql. How ever, I have encounter a problem: When I need to search same lastname in the form, it cannot be found.
I made a control form as custom search form, and works fine to search,
$Apellido = sc_sql_injection({Apellido});
$sql = “SELECT
IDPERSONA
FROM PERSONAS
WHERE Apellido = AES_ENCRYPT($Apellido,‘password’)”;
sc_lookup(rs, $sql);
if(count({rs}) == 0)
{
sc_error_exit();
}
else
{
$return = {rs[0][0]};
$_SESSION[“IDRET”]=$return;
};
however I dont know how to recive the session parameter inmain form and positioning the match record. Any suggestion ?
[QUOTE=mstopkey;13177]Hello all. Just in case anyone was needed to accomplish AES Encryption-Decryption, I though I would share what we came up with that works very well.
Form/ onAfterInsert:
/**
// SQL statement parameters
$salt = ‘/path_to_salt_file/.salt’; // Create a file on your server named .salt and put a super secret password in it with many random characters. Make sure it is readable by the web service user.
$fp = fopen( $salt, ‘r’ );
$file_contents = fread( $fp, filesize( $salt ) );
$file_contents = rtrim($file_contents);
fclose( $fp );
$update_table = ‘my_table’; // Table name
$update_where = “my_data_column_record_id = ‘[we_used_a_variable_on_the_field_in_the_form]’”; // Where clause
$update_fields = array( // Field list, add as many as needed
“my_column = aes_encrypt(my_column, ‘$file_contents’)”,
);
// Update record
$update_sql = ‘UPDATE ’ . $update_table
. ’ SET ’ . implode(’, ', $update_fields)
. ’ WHERE ’ . $update_where;
sc_exec_sql($update_sql);
To decrypt:
Form/onLoadRecord
// Decrypt record
$salt = ‘/path_to_salt_file/.salt’;
$fp = fopen( $salt, ‘r’ );
$file_contents = fread( $fp, filesize( $salt ) );
$file_contents = rtrim($file_contents);
fclose( $fp );
$check_sql = “SELECT aes_decrypt(my_column, ‘$file_contents’)”
. " FROM my_table"
. " WHERE record_id = ‘" . {my_field_record_id} . "’";
sc_lookup(rs, $check_sql);
if (isset({rs[0][0]})) // Row found
{
{my_field} = {rs[0][0]};
}
else // No row found
{
{my_field} = ‘’;
}
Note: For tigher security, place .salt file outside of your web root. You can even locate it on a totally separate server.
Mark[/QUOTE]