Download ChaCha20 Poly1305 PHP Class

Result:

plaintext:Lorem Ipsum is simply dummy text of the printing and typesetting industry...

r_key:c406e3627a624c2f7858d8729f49dfdf76e7d989
aad:7aabe76b4ee1c27624d055baf45a8a021f6147a2
Iv:4f5ad309b5a5eb7c4479ef58f1eb66fba686ca9d

crypt:e836c0b64606d6d878b267b5daeaaff3e129352bb16c28c0a1a5d452781146c0ce1a53831bb466593dcf192bd8ee4a706c52d2bd3d978872d380c94f18e215171088336ccca3b55c23d7774b6cb11ffc1fdabeefb78045428906890a

decrypt:Lorem Ipsum is simply dummy text of the printing and typesetting industry...

Code example:

<?php
include("AEAD_CHACHA20_POLY1305.php");
$x = new AEAD_CHACHA20_POLY1305;
$plaintext = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry...';
$r_key = sha1(sha1(sha1(mt_rand(0, 99999) + time())));
$aad = sha1(sha1(sha1(mt_rand(0, 99999) + time())));
$Iv = sha1(sha1(sha1(mt_rand(0, 99999) + time())));
$crypt = $x->chacha20_aead_encrypt($aad, $Key, $Iv, '07000000', $plaintext);
$decrypt = $x->chacha20_aead_decrypt($aad, $Key, $Iv, '07000000', $crypt);
$out = '<pre>';
$out .= "plaintext:\t".$plaintext."\n\n";
$out .= "r_key:\t".$r_key."\n";
$out.= "aad:\t".$aad."\n";
$out .= "Iv:\t".$Iv."\n\n";
$out .= "crypt:\t".$crypt."\n\n";
$out .= "decrypt:\t".$decrypt."\n\n";
$out .= '</pre>';
echo $out;
?>

КОНЬЯКОВ.ру > pubs > phpclasses > chacha20-and-poly130