Skip to content
/ xxtea Public

Implementation of the (corrected) Block TEA encryption algorithm in modern C++ with PHP bindings

Notifications You must be signed in to change notification settings

menezes-/xxtea

Repository files navigation

xxtea

Implementation of the corrected Block TEA encryption algorithm in modern C++.

It focuses on encrypting strings but it can be easily modified to encrypt binary data (take a look at the encode and decode functions).

This is a header only library so you just need to copy xxtea.hpp to your src folder and #include it.

Usage

#include <iostream>
#include "xxtea.hpp"

int main() {
  std::string secret{"super secret string"};
  
  auto encrypted = xxtea::encrypt(test, "hunter2");
  // encrypted is a std::vector<std::uint32_t>, you can serialize however you want (an example of that is in the xxtea-php.cpp file)
  // if your password is less than 128 bits it will be padded
  
  std::cout << xxtea::decrypt(encrypted, "hunter2") << '\n';
  
  return 0;
}

PHP extension

There's also a PHP extension inside xxtea-php, you can compile it using CMake. To be able to compile it you must have PHP-CPP installed. Once you have PHP-CPP installed build and install the PHP extension is very simple:

make
sudo make install
# enable it on your php installation eg: 
sudo cp xxtea.ini /usr/local/etc/php/conf.d/

And you're done