Ok so it's been a while, im using SS3.12 and the previous function no longer work, well thats not 100% true they do indeed encrypt the data but they don't decrypt. Anyone got any pointers please.
public function onBeforeWrite() {
$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('123'), 0, $ks);
/* Intialize encryption */
mcrypt_generic_init($td, $key, $iv);
//$toEncrypt = $this->getField("FirstName");
$toEncrypt = array (
$this->getField("FirstName"),
$this->getField("Surname")
);
$encrypted = array();
//$encrypted = mcrypt_generic($td, $toEncrypt);
foreach ($toEncrypt as $toBeEncrypted) {
if(!$toBeEncrypted){
array_push($encrypted, $toBeEncrypted);
} else {
$encryptedValue = mcrypt_generic($td, $toBeEncrypted);
array_push($encrypted, $encryptedValue);
}
}
//$toWrite = base64_encode($encrypted);
$this->FirstName = base64_encode($encrypted[0]);
$this->Surname = base64_encode($encrypted[1]);
/* Terminate encryption handler */
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
parent::onBeforeWrite();
}
the decrypt function,
protected function decryptInfo($toDecrypt) {
/* 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('123'), 0, $ks);
/* Intialize encryption */
mcrypt_generic_init($td, $key, $iv);
//$sendToDec = base64_decode($toDecrypt2);
/* Decrypt encrypted string */
if(!$toDecrypt){
return "";
}
$decrypted = mdecrypt_generic($td, base64_decode($toDecrypt));
/* Terminate decryption handle and close module */
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $decrypted;
}
and finally the calling function to display the data on the page,
protected function getTheFirstName() {
$toDecrypt = $this->getField("FirstName");
$decrypted = $this->decryptInfo($toDecrypt);
return $decrypted;
}
I have no errors and nothing to go on, anyone able to help?
Mick