コード例 #1
0
ファイル: FFXRadixTest.php プロジェクト: jan2000/ffxradix
 public function test()
 {
     $full_key = hex2bin('2b7e151628aed2a6abf7158809cf4f3cef4359d8d580aa4f7f036d6f04fc6a94');
     $tests = [['AES-128', '', '0123456789', '2433477484', 10], ['AES-128', '9876543210', '0123456789', '6124200773', 10], ['AES-128', '7777pqrs777', '0123456789abcdefghi', 'a9tv40mll9kdu509eum', 36], ['AES-192', '', '0123456789', '2830668132', 10], ['AES-192', '9876543210', '0123456789', '2496655549', 10], ['AES-192', '7777pqrs777', '0123456789abcdefghi', 'xbj3kv35jrawxv32ysr', 36], ['AES-256', '', '0123456789', '6657667009', 10], ['AES-256', '9876543210', '0123456789', '1001623463', 10], ['AES-256', '7777pqrs777', '0123456789abcdefghi', 'xs8a0azh2avyalyzuwd', 36], ['AES-128', '2718281828', '314159', '535005', 10], ['AES-128', '7777777', '999999999', '658229573', 10], ['AES-128', 'TQF9J5QDAGSCSPB1', 'c4xpwulbm3m863jh', 'c8aq3u846zwh6qzp', 36], ['AES-128', '', '0000000000000000000000000000000000000000000000000', '80a5d84e29d517ed24d38a6e0aba502dc457a56880ffa58eb', 16], ['AES-128', '', '', '', 2]];
     $ffx = new FFXRadix();
     foreach ($tests as $row) {
         $cipher = $row[0];
         $input = $row[2];
         $radix = $row[4];
         $tweak = $row[1];
         $output = $row[3];
         $ffx->setCipher($cipher);
         $key = substr($full_key, 0, substr($cipher, -3) / 8);
         $enc = $ffx->encrypt($input, $radix, $key, $tweak);
         $this->assertSame($output, $enc);
         $dec = $ffx->decrypt($enc, $radix, $key, $tweak);
         $this->assertSame($input, $dec);
     }
 }
コード例 #2
0
ファイル: exampe.php プロジェクト: jan2000/ffxradix
<?php

require __DIR__ . '/vendor/autoload.php';
use Janv\FFXRadix\FFXRadix;
// Key must be a 16 byte long string if AES-128 (default) is used
$key = hex2bin('00000000000000000000000000000000');
// Tweak can be anything
$tweak = hex2bin('0123456789abcdef');
$ffx = new FFXRadix();
// Encrypt a 16 decimal number (radix = 10)
$enc = $ffx->encrypt(sprintf('%016d', 1), 10, $key, $tweak);
// Outputs 1299047952447293
echo "{$enc}\n";
// Decrypt
$dec = $ffx->decrypt($enc, 10, $key, $tweak);
// Outputs 0000000000000001
echo "{$dec}\n";