views:

29

answers:

1

Does anybody know any php alternative to coldfusion's cfusion_encrypt?

Currently cfusion_encrypt is still used via curl and its trouble since the cf server keeps going down. It would be a lot better if anyone could give me a php alternative to this function.

Thanks.

A: 

You could use mcrypt (http://php.net/manual/en/book.mcrypt.php)

Like this? See listing 4 http://onlamp.com/pub/a/php/2001/07/26/encrypt.html?page=3

<?php

// Designate string to be encrypted
$string = "Applied Cryptography, by Bruce Schneier, is 
a wonderful cryptography reference.";

// Encryption/decryption key
$key = "Four score and twenty years ago";

// Encryption Algorithm
$cipher_alg = MCRYPT_RIJNDAEL_128;

// Create the initialization vector for added security.
$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg, 
MCRYPT_MODE_ECB), MCRYPT_RAND);

// Output original string
print "Original string: $string <p>";

// Encrypt $string
$encrypted_string = mcrypt_encrypt($cipher_alg, $key, 
$string, MCRYPT_MODE_CBC, $iv);

// Convert to hexadecimal and output to browser
print "Encrypted string: ".bin2hex($encrypted_string)."<p>";

$decrypted_string = mcrypt_decrypt($cipher_alg, $key, 
$encrypted_string, MCRYPT_MODE_CBC, $iv);

print "Decrypted string: $decrypted_string";

?>

Executing Listing 4 will produce the following output:

Original string: Applied Cryptography, by Bruce Schneier, is a wonderful cryptography reference.

Encrypted string: 02a7c58b1ebd22a9523468694b091e60411cc4dea8652bb8072 34fa06bbfb20e71ecf525f29df58e28f3d9bf541f7ebcecf62b c89fde4d8e7ba1e6cc9ea24850478c11742f5cfa1d23fe22fe8 bfbab5e

Decrypted string: Applied Cryptography, by Bruce Schneier, is a wonderful cryptography reference.

jfrobishow
hi. thanks for the reply. do u know what cipher will i have to use so that i can get the same results with cfusion_encrypt?
uji
By default CF will use the CFMX_COMPAT algorithm... I am not sure you will have to experiment, it might not be available to PHP if it's proprietary.
jfrobishow