[FX.php List] Encrypting/decrypting in PHP
Stephen Grant
stephen.grant at 724.com.au
Tue Sep 20 15:47:13 MDT 2011
The following is just one of the php encryption functions we use regularly. This particular set uses CAST_128 as the algorithym
but that can be changed extremely easily. If you use RJINDEL encryption then you can use Troi's plugin for decrypting directly in FileMaker. However my preferred method is not to use a plugin in FileMaker at all but to use SSL to communicate with our web server for posting and returning encrypted content.
Of course you can use the exact reverse of this to decrypt as well and the great thing is, its lightning quick. We process somewhere in the neighborhood of 4-5 transactions per second 24 hours per day and it hardly moves the processor from idle....
We chose this method as our client (one of the four banks in Australia) required ultra secure communication and storage and this passed their own security requirements.
Anyway, here's a snippet of the function.
function _encrypt($str) {
$block = mcrypt_get_block_size('cast_128', 'cbc');
$pad = $block - (strlen($str) % $block);
$str .= str_repeat(chr($pad), $pad);
return base64_encode(mcrypt_encrypt(MCRYPT_CAST_128, $key, $str, MCRYPT_MODE_CBC));
}
$str --> The string to be encrypted
$key --> the encryption key to set
The result of this encryption is a base64 encoded string that is simple to store in FileMaker.
You might also find it helpful to first JSON encode your data before passing it to be encrypted and then JSON decoding it on retrieval; it makes data management much easier.
FYI there is a great website called www.tools4noobs.com that has an online ecryption/decription set that is very useful
for debugging encrypted matters.
Steve
----- Original Message -----
From: "Bob Patin" <bob at patin.com>
To: "FX.php Discussion List" <fx.php_list at mail.iviking.org>
Sent: Wednesday, 21 September, 2011 12:58:01 AM
Subject: Re: [FX.php List] Encrypting/decrypting in PHP
Stephen,
How do you decrypt when desired? In PHP or in FileMaker?
Bob Patin
Longterm Solutions LLC
bob at longtermsolutions.com
615-333-6858
http://www.longtermsolutions.com
FileMaker 9, 10 & 11 Certified Developer
Member of FileMaker Business Alliance and FileMaker TechNet
--
Twitter: bobpatin
Google+: http://www.longtermsolutions.com/plus
AIM: longterm1954
iChat: bobpatin
--
Expert FileMaker Consulting
FileMaker Hosting for all versions of FileMaker
On Sep 19, 2011, at 11:56 AM, Stephen Grant wrote:
We do this all the time. Use:
http://php.net/manual/en/function.mcrypt-encrypt.php
Then base64 encode the results.
I will send an example tomorrow.
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
_______________________________________________
FX.php_List mailing list
FX.php_List at mail.iviking.org
http://www.iviking.org/mailman/listinfo/fx.php_list
More information about the FX.php_List
mailing list