1--TEST--
2openssl_decrypt() tests dependent on openssl_encrypt
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, 0, $iv);
17$output = openssl_decrypt($encrypted, $method, $password, 0, $iv);
18var_dump($output);
19$encrypted = openssl_encrypt($data, $method, $password, OPENSSL_RAW_DATA, $iv);
20$output = openssl_decrypt($encrypted, $method, $password, OPENSSL_RAW_DATA, $iv);
21var_dump($output);
22// if we want to manage our own padding
23$padded_data = $data . str_repeat(' ', 16 - (strlen($data) % 16));
24$encrypted = openssl_encrypt($padded_data, $method, $password, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
25$output = openssl_decrypt($encrypted, $method, $password, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
26var_dump(rtrim($output));
27// if we want to prefer variable length cipher setting
28$encrypted = openssl_encrypt($data, "bf-ecb", $password, OPENSSL_DONT_ZERO_PAD_KEY);
29$output = openssl_decrypt($encrypted, "bf-ecb", $password, OPENSSL_DONT_ZERO_PAD_KEY);
30var_dump($output);
31?>
32--EXPECT--
33string(45) "openssl_encrypt() and openssl_decrypt() tests"
34string(45) "openssl_encrypt() and openssl_decrypt() tests"
35string(45) "openssl_encrypt() and openssl_decrypt() tests"
36string(45) "openssl_encrypt() and openssl_decrypt() tests"
37