Ejemplo n.º 1
0
function verify(string $key, string $nonce, string $aad, string $ciphertext, string $tag) : bool
{
    $cipher = new Cipher();
    $context = $cipher->init($key, $nonce);
    $cipher->aad($context, $aad);
    $cipher->verify($context, $ciphertext);
    try {
        $cipher->finish($context, $tag);
        return true;
    } catch (AuthenticationException $e) {
        return false;
    }
}
Ejemplo n.º 2
0
<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);
require_once dirname(__FILE__) . '/../Cipher.php';
Cipher::$defaultOptions['cipher'] = MCRYPT_RIJNDAEL_256;
$out = Cipher::init($_REQUEST['options'])->{$_REQUEST['method']}($_REQUEST['subject']);
if (!$_REQUEST['options']['base']) {
    $out = preg_replace_callback('/[\\x00-\\x20\\x7F-\\xFF]/', 'make_printable', $out);
}
echo $out;
function make_printable($match)
{
    $hex = dechex(ord($match[0]));
    $hex = strtoupper($hex);
    if (strlen($hex) == 1) {
        return '\\x0' . $hex;
    } else {
        return '\\x' . $hex;
    }
}
Ejemplo n.º 3
0
<pre><?php 
ini_set('display_errors', 1);
error_reporting(E_ALL);
require_once dirname(__FILE__) . '/../Cipher.php';
Cipher::$defaultOptions['base'] = 62;
$begin = microtime(true);
foreach (range(1000, 1050) as $i) {
    echo "\n{$i} =&gt; " . ($o = Cipher::init()->encrypt($i)) . ' =&gt; ' . Cipher::init()->decrypt($o);
}
$end = round(microtime(true) - $begin, 3);
echo "\nCompleted in {$end} seconds";
Ejemplo n.º 4
0
<pre><?php 
ini_set('display_errors', 1);
error_reporting(E_ALL);
require_once dirname(__FILE__) . '/../Cipher.php';
Cipher::$defaultOptions['base'] = 62;
$begin = microtime(true);
foreach (range(1, 3) as $i) {
    $password = uniqid();
    echo "\n{$i} =&gt; " . ($o = Cipher::init()->hashPassword($password)) . ' =&gt; matches? ' . (int) Cipher::init()->validatePassword($password, $o);
}
$end = round(microtime(true) - $begin, 3);
echo "\nCompleted in {$end} seconds";