function getPassword($pwd = null, $iv_field = "iv") { if (is_null($pwd)) { $pwd = $this->password; if (!$this->password) { return ""; } } try { $master_key_filepath = CAppUI::conf("master_key_filepath"); $master_key_filepath = rtrim($master_key_filepath, "/"); if (CExchangeSource::checkMasterKeyFile($master_key_filepath)) { CAppUI::requireLibraryFile("phpseclib/phpseclib/Crypt/AES"); CAppUI::requireLibraryFile("phpseclib/phpseclib/Crypt/Random"); $cipher = new Crypt_AES(CRYPT_AES_MODE_CTR); $cipher->setKeyLength(256); $keyAB = file($master_key_filepath . "/.mediboard.key"); if (count($keyAB) == 2) { $cipher->setKey($keyAB[0] . $keyAB[1]); $ivToUse = $this->{$iv_field}; if (!$ivToUse) { $clear = $pwd; $this->store(); return $clear; } $cipher->setIV($ivToUse); $decrypted = rtrim(base64_decode($pwd), ""); $decrypted = $cipher->decrypt($decrypted); if ($decrypted) { return $decrypted; } } } } catch (Exception $e) { return $pwd; } return $pwd; }