![]() |
Sergey Kornilov admin 5/25/2009 |
You need to encrypt fields before sending data to the database. Use BeforeAdd/BeforeEdit events for this purpose. |
S
|
salus1DevClub member 8/4/2009 |
Hi, |
X
|
xliner 8/4/2009 |
Simple two PHP code snippets (encryption/decryption), turning things by means of ASCII character code + a NUMBER (in this case 2, changeable to whatsoever higher one): |
S
|
salus1DevClub member 8/4/2009 |
Thanks for taking the time to produce this example. Unfortunately the application will be storing social security numbers and credit card account numbers so I need something more industrial strength. Can anyone supply an example of encrypting / decrypting PHPRunner data fields using MCRYPT functions? |
X
|
xliner 8/4/2009 |
Thanks for taking the time to produce this example. Unfortunately the application will be storing social security numbers and credit card account numbers so I need something more industrial strength. Can anyone supply an example of encrypting / decrypting PHPRunner data fields using MCRYPT functions? Thanks!
Key: $key |
S
|
salus1DevClub member 8/4/2009 |
Outstanding, many thanks! |
X
|
xliner 8/4/2009 |
Outstanding, many thanks!
|
S
|
salus1DevClub member 8/4/2009 |
Thanks for the additional info, think I'd like to stick to the second method, though. |
S
|
salus1DevClub member 8/4/2009 |
Actually I think that Iwould have to create a field in the database to store the initialization vector in order to retrieve it during decrytion so... |
S
|
salus1DevClub member 8/4/2009 |
Final solution. Users can view and edit their encryped data but data is stored encrypted in database. |
R
|
rahulgilani 8/5/2009 |
Final solution. Users can view and edit their encryped data but data is stored encrypted in database. Ecryped data is padded (not sure how to get rid of padding yet) textvalue is the name of the varchar field to be encrypted and stored in the database. vector is the name of the varchar field in the database which retains the vector information generated during encrytion __ Create Before Record Added and Before Record Updated events as follows... $key="SecretKey"; $text=$values["textvalue"]; $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CBC); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $crypttext = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $text, MCRYPT_MODE_CBC, $iv); $values["textvalue"]=$crypttext; $values["vector"]=$iv; return true __ Format textvalue field as Custom as follows... $key="SecretKey"; $text=$data["textvalue"]; $iv=$data["vector"]; $decrypttext = mcrypt_decrypt(MCRYPT_BLOWFISH, $key, $text, MCRYPT_MODE_CBC, $iv); $value=$decrypttext;
|
R
|
rahulgilani 8/6/2009 |
To further test, I created a sample PHP script (outside of PHP Runner) and both the encryption and decryption work, albeit, the decryption contained a couple of extra characters. I'd imagine this is the "padding" that was mentioned previously. |
S
|
salus1DevClub member 8/6/2009 |
Hi, |
S
|
salus1DevClub member 8/6/2009 |
The plain text is only viewable on the List and View Pages when the field has been formatted to View As Custom as outlined above. Even when I format the field on the Add and Edit Pages to View As Custom the encrypted text is read in from the dababase without modification. I did notice that after I formatted the List Page field to use the View As Custom code that the trailing characters no longer appeared. I have no idea why. |
R
|
rahulgilani 8/6/2009 |
The plain text is only viewable on the List and View Pages when the field has been formatted to View As Custom as outlined above. Even when I format the field on the Add and Edit Pages to View As Custom the encrypted text is read in from the dababase without modification. I did notice that after I formatted the List Page field to use the View As Custom code that the trailing characters no longer appeared. I have no idea why.
|
S
|
salus1DevClub member 8/6/2009 |
Hi, |
R
|
rahulgilani 8/6/2009 |
Hi, Actually it looks like the data is decryted during export. The export mechanism must inherit the pages format. Also, the trailing characters are only visible when using FireFox, not Internet Exploder. I'll need to test using other browsers, too.
|
S
|
salus1DevClub member 8/6/2009 |
Hi, |
R
|
rahulgilani 8/6/2009 |
Hi, Seems to work properly in IE, Safari, and Opera, with trailing characters visble only in FireFox. All running on Vista via SSL.
|
B
|
barlow 8/6/2009 |
Sorry, I haven't read the whole thread, but this is how I've approached the same issue in PHPRUNNER 5.0 class Cipher {
// Encrypt the patient details
require_once("crypt.php");$cipher = new Cipher('');
function GetData($data,$field, $format)
|