@@ -1820,7 +1820,8 @@ function _api_format_user($user, $add_password = false, $loadAvatars = true)
18201820 $ result ['profile_url ' ] = api_get_path (WEB_CODE_PATH ).'social/profile.php?u= ' .$ user_id ;
18211821
18221822 // Send message link
1823- $ sendMessage = api_get_path (WEB_AJAX_PATH ).'user_manager.ajax.php?a=get_user_popup&user_id= ' .$ user_id ;
1823+ $ userIdHash = UserManager::generateUserHash ($ user_id );
1824+ $ sendMessage = api_get_path (WEB_AJAX_PATH ).'user_manager.ajax.php?a=get_user_popup&hash= ' .$ userIdHash ;
18241825 $ result ['complete_name_with_message_link ' ] = Display::url (
18251826 $ result ['complete_name_with_username ' ],
18261827 $ sendMessage ,
@@ -10615,9 +10616,23 @@ function api_decrypt_ldap_password(string $encryptedText): string
1061510616 } else {
1061610617 return false ;
1061710618 }
10619+
10620+ return api_decrypt_hash ($ encryptedText ,$ secret );
10621+ }
10622+
10623+ /**
10624+ * Decrypt sent hash encoded with secret
10625+ *
10626+ * @param $encryptedText The hash text to be decrypted
10627+ * @param $secret The secret used to encoded the hash
10628+ *
10629+ * @return string The decrypted text or false
10630+ */
10631+ function api_decrypt_hash (string $ encryptedHash , string $ secret ): string
10632+ {
1061810633 $ secret = hex2bin ($ secret );
10619- $ iv = base64_decode (substr ($ encryptedText , 0 , 16 ), true );
10620- $ data = base64_decode (substr ($ encryptedText , 16 ), true );
10634+ $ iv = base64_decode (substr ($ encryptedHash , 0 , 16 ), true );
10635+ $ data = base64_decode (substr ($ encryptedHash , 16 ), true );
1062110636 $ tag = substr ($ data , strlen ($ data ) - 16 );
1062210637 $ data = substr ($ data , 0 , strlen ($ data ) - 16 );
1062310638
@@ -10634,3 +10649,31 @@ function api_decrypt_ldap_password(string $encryptedText): string
1063410649 return false ;
1063510650 }
1063610651}
10652+
10653+ /**
10654+ * Encrypt sent data with secret
10655+ *
10656+ * @param $data The text to be encrypted
10657+ * @param $secret The secret to use encode data
10658+ *
10659+ * @return string The encrypted text or false
10660+ */
10661+ function api_encrypt_hash ($ data , $ secret )
10662+ {
10663+ $ secret = hex2bin ($ secret );
10664+ $ iv = random_bytes (12 );
10665+ $ tag = '' ;
10666+
10667+ $ encrypted = openssl_encrypt (
10668+ $ data ,
10669+ 'aes-256-gcm ' ,
10670+ $ secret ,
10671+ OPENSSL_RAW_DATA ,
10672+ $ iv ,
10673+ $ tag ,
10674+ '' ,
10675+ 16
10676+ );
10677+
10678+ return base64_encode ($ iv ) . base64_encode ($ encrypted . $ tag );
10679+ }
0 commit comments