@@ -24,10 +24,15 @@ $padded_data = $data . str_repeat(' ', 16 - (strlen($data) % 16));
24
24
$ encrypted = openssl_encrypt ($ padded_data , $ method , $ password , OPENSSL_RAW_DATA |OPENSSL_ZERO_PADDING , $ iv );
25
25
$ output = openssl_decrypt ($ encrypted , $ method , $ password , OPENSSL_RAW_DATA |OPENSSL_ZERO_PADDING , $ iv );
26
26
var_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 );
30
- var_dump ($ output );
27
+
28
+ if (in_array ("bf-ecb " , openssl_get_cipher_methods ())) {
29
+ // if we want to prefer variable length cipher setting
30
+ $ encrypted = openssl_encrypt ($ data , "bf-ecb " , $ password , OPENSSL_DONT_ZERO_PAD_KEY );
31
+ $ output = openssl_decrypt ($ encrypted , "bf-ecb " , $ password , OPENSSL_DONT_ZERO_PAD_KEY );
32
+ var_dump ($ output === $ data );
33
+ } else {
34
+ var_dump (true );
35
+ }
31
36
32
37
// It's okay to pass $tag for a non-authenticated cipher.
33
38
// It will be populated with null in that case.
@@ -39,5 +44,5 @@ var_dump($tag);
39
44
string(45) "openssl_encrypt() and openssl_decrypt() tests"
40
45
string(45) "openssl_encrypt() and openssl_decrypt() tests"
41
46
string(45) "openssl_encrypt() and openssl_decrypt() tests"
42
- string(45) "openssl_encrypt() and openssl_decrypt() tests"
47
+ bool(true)
43
48
NULL
0 commit comments