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
./buildconfto rebuild PHP's configure script.
-
Compile php with option:
--enable-xxteato build bundled into PHP module--enable-xxtea=sharedto build dinamycally loadable module
-
Unpack contents of the package.
-
Run
phpizescript, which will prepare environment for building XXTEA package.
-
Run
./configure --enable-xxtea=sharedto generate makefile.
-
Run
maketo build XXTEA extension library. It will be placed into ./modules folder.
-
Run
make installto install XXTEA extension library into PHP
-
Run:
pecl install xxteaThat'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!";
}