xref: /PHP-5.3/ext/openssl/tests/011.phpt (revision 2655e63e)
1--TEST--
2openssl_encrypt() and openssl_decrypt() tests
3--SKIPIF--
4<?php if (!extension_loaded("openssl")) print "skip"; ?>
5--FILE--
6<?php
7$data = "openssl_encrypt() and openssl_decrypt() tests";
8$method = "AES-128-CBC";
9$password = "openssl";
10
11$ivlen = openssl_cipher_iv_length($method);
12$iv    = '';
13srand(time() + ((microtime(true) * 1000000) % 1000000));
14while(strlen($iv) < $ivlen) $iv .= chr(rand(0,255));
15
16$encrypted = openssl_encrypt($data, $method, $password, false, $iv);
17$output = openssl_decrypt($encrypted, $method, $password, false, $iv);
18var_dump($output);
19$encrypted = openssl_encrypt($data, $method, $password, true, $iv);
20$output = openssl_decrypt($encrypted, $method, $password, true, $iv);
21var_dump($output);
22?>
23--EXPECT--
24string(45) "openssl_encrypt() and openssl_decrypt() tests"
25string(45) "openssl_encrypt() and openssl_decrypt() tests"
26
27