2008-07-18 23:52:01 +00:00
|
|
|
--TEST--
|
|
|
|
openssl_encrypt() and openssl_decrypt() tests
|
|
|
|
--SKIPIF--
|
|
|
|
<?php if (!extension_loaded("openssl")) print "skip"; ?>
|
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
$data = "openssl_encrypt() and openssl_decrypt() tests";
|
|
|
|
$method = "AES-128-CBC";
|
|
|
|
$password = "openssl";
|
|
|
|
|
2010-05-19 21:18:16 +00:00
|
|
|
$ivlen = openssl_cipher_iv_length($method);
|
|
|
|
$iv = '';
|
|
|
|
srand(time() + ((microtime(true) * 1000000) % 1000000));
|
|
|
|
while(strlen($iv) < $ivlen) $iv .= chr(rand(0,255));
|
|
|
|
|
|
|
|
$encrypted = openssl_encrypt($data, $method, $password, false, $iv);
|
|
|
|
$output = openssl_decrypt($encrypted, $method, $password, false, $iv);
|
2008-07-18 23:52:01 +00:00
|
|
|
var_dump($output);
|
2010-05-19 21:18:16 +00:00
|
|
|
$encrypted = openssl_encrypt($data, $method, $password, true, $iv);
|
|
|
|
$output = openssl_decrypt($encrypted, $method, $password, true, $iv);
|
2008-07-18 23:52:01 +00:00
|
|
|
var_dump($output);
|
|
|
|
?>
|
|
|
|
--EXPECT--
|
|
|
|
string(45) "openssl_encrypt() and openssl_decrypt() tests"
|
|
|
|
string(45) "openssl_encrypt() and openssl_decrypt() tests"
|
|
|
|
|