23001 Posts in 11854 Topics by 2828 members
Page: 1 2
|Go to End||Next >|
14 December 2010 at 5:02am
I'm working on an application that may need to store sensitive medical information and I was wondering can fields be encrypted/decrypted using AES_ENCRYPT() and AES_DECRYPT() or others using standard DataObject Write and Get methods? Or would I need to use an onBeforeWrite() and create functions to Manually Decrypt later?
20 December 2010 at 2:10pm
I've decided to try using onBeforeWrite. here is my code:
$modes = mcrypt_list_modes();
/* Open the cipher */
$td = mcrypt_module_open('rijndael-128', '', 'ecb', '');
/* Create the IV and determine the keysize length, use MCRYPT_RAND
* on Windows instead */
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
$ks = mcrypt_enc_get_key_size($td);
/* Create key */
$key = substr(md5('very secret key'), 0, $ks);
/* Intialize encryption */
mcrypt_generic_init($td, $key, $iv);
$toEncrypt = $this->FirstName;
$encrypted = mcrypt_generic($td, $toEncrypt);
/* Terminate encryption handler */
The data encrypts but won't write to the DB. is this because SilverStripe is escaping any non standard alphanumeric characters? If so how do I override
8 December 2011 at 7:50pm
this is something i may also need to do, did you find a suitable solution?
9 December 2011 at 3:03am
Yes, I found a solution. It turns out AES_ENCRYPT() converts the data into a binary blob, so you need to use base64_encode on the value before you can write it to the Database and base64_decode on the other end.
A word of warning on host choices though, the client used GoDaddy VPS against my advice and their default PHP install doesn't include the MCRYPT module so when I installed it on the server everything failed until I manually patched the MCRYPT module onto the server.
10 December 2011 at 12:00am
Cheers for that,
I'm just looking at the code now to see if it's something I can do easily enough.
3 May 2012 at 2:59am
I'm having a play finally with the code and like you it won't write to the database, I know you mentioned that it needed to be base64 encoded is there any chance you can paste your code where you do this I have tried it with no luck so far.
3 May 2012 at 7:27pm
Many thanks for that, i had missed out the = in theand as im doing this on a decorator i had also missed the
$this->FirstName = base64_encode($encrypted);as well.
I'm entering this data via modeladmin how would i call the decrypt function for the couple of encrypted fields in the CMS?
Page: 1 2
|Go to Top||Next >|