@@ -106,6 +106,8 @@ public static function get($field, $source = null, $default = null, $possible_va
106106 $ value = isset ($ source [$ field ]) ? $ source [$ field ] : $ default ;
107107 } else if (is_object ($ source )) {
108108 $ value = isset ($ source ->{$ field }) ? $ source ->{$ field } : $ default ;
109+ } else {
110+ $ value = $ default ;
109111 }
110112
111113 if ($ possible_values ) {
@@ -231,10 +233,6 @@ public static function in_string($needle, $string) {
231233 } else return stripos ($ string , $ needle ) !== false ;
232234 }
233235
234- public static function hash ($ str ) {
235- return hash ('sha256 ' , $ str );
236- }
237-
238236 public static function save_session_result ($ data ) {
239237 $ uuid = self ::uuid ();
240238 $ _SESSION [$ uuid ] = json_encode ($ data );
@@ -582,7 +580,7 @@ public static function encrypt($data, $key, $iv) {
582580 $ output = false ;
583581 $ encrypt_method = "AES-256-CBC " ;
584582 // hash
585- $ key = self :: hash ( $ key );
583+ $ key = hash_hmac ( ' sha256 ' , $ data , $ iv );
586584
587585 // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
588586 $ iv = substr ($ iv , 0 , 16 );
@@ -599,7 +597,7 @@ public static function decrypt($data, $key, $iv) {
599597 $ output = false ;
600598 $ encrypt_method = "AES-256-CBC " ;
601599 // hash
602- $ key = self :: hash ( $ key );
600+ $ key = hash_hmac ( ' sha256 ' , $ data , $ iv );
603601
604602 // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
605603 $ iv = substr ($ iv , 0 , 16 );
0 commit comments