1. How do I encrypt a field that I save in the database table, such as an SSN field, that I then use on the search screen to search for it. For example:
On my edit form I have a field named cust_SSN. I want to encrypt it and save it in the database (simple). There are MANY methods to do this and I am currently using the BEFORE SAVE to run a procedure that will encrypt the SSN field before it is saved. This part is done.
The PROBLEM: Searching for those records using the same cust_SSN field.
I need to be able to perform the form search USING the cust_SSN field. If I use my current and/or many other encryption routines to encrypt the data and save it in the database. I MUST always enter the FULL SSN when I search for the SSN. Because, for example, if I search for some subset of the SSN 123-45-6789 (last 4 = 6789), those last 4 numbers will NEVER be in the encrypted field in the same format with my current encryption routine. Someone suggested using base64_encode because they will always encrypt to be the same pattern. However, that doesn't seem to help because base64_Encode would then not be a good way to encrypt that field. It would be easily unencrypted, Right?
What Im trying to figure out is HOW do I use the search form, to enter an SSN (even the full SSN) encrypt it BEFORE I search for it and then have the results show the unencrypted data that is returned? So on the search results I would see all the records that contained 6789 as the last four of the SSN?
Kev1n suggested this: p
I used the newest nuform.js and made sure that nuOnSearchAction was in it. I declared the nuOnSearchAction() function. I called the PHP function (that I created in the Procedures), and then looked at the nuRunPHPHidden & nuJavascriptCallback to see what they did. It didn't work.Declare a function nuOnSearchAction() in your form's Custom Code. Call a PHP Procedure in it to encrypt the search value and use nuJavascriptCallback to Refresh the Browse Screen. You will need the updated nuform.js:
function nuOnSearchAction() {
Sstring1=nuRunPHPHidden('encryptString($('#nuSearchField'))','0);
nuJavascriptCallback($string1);
result = false;
}
I know this function WILL NOT work as is. nuRunPHPHidden returns NOTHING. It is used to call the PHP Procedure that I created to encrypt the nuSearchfield. nuJavascriptCallback is a PHP function that calls a Javascript function or code.
1. Where does that Javascript have to exist? In the Custom Code of the form?
2. How do I pass the encrypted data string that nuRunPHPHidden('encryptString($('#nuSearchField'))','0); generated in the encryptString PHP procedure, to be used in the nuJavascriptCallback() function? If the nuRunPHPHidden returns NOTHING how do I get that data into the nuJavascriptCallback() function? Is this >>nuRunPHPHidden('encryptString($('#nuSearchField'))','0);<< even the proper way to grab what was entered in the search field and pass it to my PHP encryptString procedure?
3. OR do I call the nuJavascriptCallback() PHP function within my encryptString() PHP procedure? But then how does it CHANGE the search criteria on the screen before it searches the database?
Im not asking for help writing the code to encrypt the fields, Im asking for the overview on how these functions work and should be used to actually change the search criteria before the search occurs, then how to display the returned data in an unencrypted format in the record list? The definitions of the functions in the wiki's DO NOT provide for how to use them in real life.
For example, the nuRunPHPhidden example shows: "nuRunPHPHidden('INV', 1);" and states: "If placed on an Object's click event, it will run a Procedure on the server without anything visibly happening. " Procedure doesn't even link to what a procedure is. I had to guess at what that was. Then it says "If you want some JavaScript to run after the Procedure, you can add that within that Procedure with nuJavascriptCallback(). " Again how is this helpful in writing anything to affect a screen, a form, an object on the form, or in my case THE SEARCH criteria before it runs. Referring someone to the "Manual" or "Wiki" or the function itself does not help in any way because there is nothing there that provides real world examples on how to actually use it to do anything. Take a look at the PHP.net and how each function has a lot of examples in commentary, that's helpful.
Does this make sense at all or is NOBODY encrypting private data in their databases?