XXTEA is a fast and secure encryption algorithm. This is a XXTEA extension for PHP.
It is different from the original XXTEA encryption algorithm. It encrypts and decrypts string instead of uint32 array, and the key is also string.
There are many ways to build the package. Below you can find details for most useful ways of package building:
-
Create ext/xxtea folder in the php-source-folder. Copy all files from the package into created folder.
-
Run
./buildconf
to rebuild PHP's configure script.
-
Compile php with option:
--enable-xxtea
to build bundled into PHP module--enable-xxtea=shared
to build dinamycally loadable module
-
Unpack contents of the package.
-
Run
phpize
script, which will prepare environment for building XXTEA package.
-
Run
./configure --enable-xxtea=shared
to generate makefile.
-
Run
make
to build XXTEA extension library. It will be placed into ./modules folder.
-
Run
make install
to install XXTEA extension library into PHP
-
Run:
pecl install xxtea
That's all.
<?php
$str = "Hello World! 你好,**!";
$key = "1234567890";
$encrypt_data = xxtea_encrypt($str, $key);
$decrypt_data = xxtea_decrypt($encrypt_data, $key);
if ($str == $decrypt_data) {
echo "success!";
} else {
echo "fail!";
}