Skip to content

xxtea/xxtea-ruby

Repository files navigation

XXTEA for Ruby

XXTEA logo

Build Status Gem Gem Gem Gems Gems

Introduction

XXTEA is a fast and secure encryption algorithm. This is a XXTEA library for Ruby.

It is different from the original XXTEA encryption algorithm. It encrypts and decrypts raw binary data instead of 32bit integer array, and the key is also the raw binary data.

Installation

gem install xxtea-ruby

Usage

# encoding: utf-8
require "xxtea"
text = "Hello World! 你好,中国!"
key = "1234567890"
encrypt_data = XXTEA.encrypt(text, key)
decrypt_data = XXTEA.decrypt_utf8(encrypt_data, key)
puts (text == decrypt_data ? "success!" : "fail!");
XXTEA.decrypt_utf8(encrypt_data, key) == XXTEA.decrypt(encrypt_data, key).force_encoding(Encoding::UTF_8)

Note

decrypt_utf8 is an alias of decrypt in ruby 1.8.x or lower version.