Skip to content

Commit b6274f0

Browse files
authored
create the # usage section
1 parent b9917f2 commit b6274f0

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
11
# php-xtea
22
XTEA implementation in PHP
33

4+
# usage
5+
note that the entire library is binary-safe, data-to-encrypt and encryption keys and data-to-decrypt and the resulting decrypted data may be binary data.
6+
7+
the signature for XTEA::encrypt is
8+
```php
9+
public static function encrypt(string $data, array $keys,
10+
int $padding_scheme = self::PAD_0x00, int $rounds = 32) : string
11+
```
12+
- string $data is the data to be encrypted
13+
- array $keys is an array containing the 4 xtea keys as integers (if you have a binary key, you can convert it to an int array with the XTEA::binary_key_to_int_array() function)
14+
- int $padding_scheme is the padding scheme to use, there are 3 padding schemes: the default `XTEA::PAD_0x00` will right-pad with null-bytes, `XTEA::PAD_RANDOM` will right-pad with cryptographically-secure random bytes, and `XTEA::PAD_NONE` will not do any padding but throw an InvalidArgumentException if padding is required.
15+
- int $rounds is how many rounds to encrypt, the default is 32, and 32 is recommended by XTEA's designers `Roger Needham` and `David Wheeler`, 0 rounds will effectively result in no encryption whatsoever with only padding being applied.
16+
17+
the return string is the encrypted binary data.
18+
19+
the signature for XTEA::decrypt is
20+
```php
21+
public static function decrypt(string $data, array $keys, int $rounds = 32) : string
22+
```
23+
- string $data is the encrypted binary data
24+
- array $keys is an array containing the 4 xtea keys as integers (if you have a binary key, you can convert it to an int array with the XTEA::binary_key_to_int_array() function)
25+
- int $rounds is how many rounds was used during encryption. the default is 32, and 32 is recommended by XTEA's designers `Roger Needham` and `David Wheeler`, and 0 rounds effectively means that no encryption was applied at all.
26+
27+
the return string is the decrypted (binary?) data.
28+
29+
the signature for XTEA::binary_key_to_int_array is
30+
```php
31+
public static function binary_key_to_int_array(string $key, int $padding_scheme = self::PAD_0x00) : array
32+
```
33+
- string $key is the (binary?) encryption key, it can be anywhere between 0-16 bytes (inclusive), except if the padding scheme is XTEA::PAD_NONE, in which case it needs to be _exactly_ 16 bytes long. if the key is longer than 16 bytes, an InvalidArgumentException is thrown.
34+
- int $padding_scheme is the padding scheme to use when the key is less than 16 bytes long, 2 padding schemes are supported: `XTEA::PAD_0x00` will right-pad it with null-bytes, and `XTEA::PAD_NONE` will not do any padding, but throw an InvalidArgumentException if the key length is not exactly 16 bytes long. (i intentionally did not add support for XTEA::PAD_RANDOM here because i believe that supporting *ANY* non-deterministic padding scheme for the key is a bad idea.)
35+
36+
the return is an array containing the 4 resulting XTEA keys as php integers, which can be used with XTEA::encrypt and XTEA::decrypt
37+
438
# examples
539

640
```php

0 commit comments

Comments
 (0)