public static function decryptLink($link, $ignore_exceptions = false)
 {
     if (preg_match('/^.*?!(?P<data>[0-9a-z_-]+)!(?P<hash>[0-9a-f]+)/i', trim(str_replace('/', '', $link)), $match)) {
         if (hash_hmac(self::HMAC_ALGO, $match['data'], md5(MASTER_KEY)) != $match['hash']) {
             throw new Exception_MegaCrypterLinkException(self::LINK_ERROR);
         } else {
             if (!$ignore_exceptions && BLACKLIST_LEVEL >= self::BLACKLIST_LEVEL_MC && self::isBlacklistedLink($match['data'])) {
                 throw new Exception_MegaCrypterLinkException(self::BLACKLISTED_LINK);
             } else {
                 list($secret, $file_id, $file_key, $pass, $extra, $auth) = explode(self::SEPARATOR, gzinflate(Utils_CryptTools::aesCbcDecrypt(Utils_MiscTools::urlBase64Decode($match['data']), Utils_MiscTools::hex2bin(MASTER_KEY), md5(MASTER_KEY, true))));
                 if (!$ignore_exceptions && BLACKLIST_LEVEL == self::BLACKLIST_LEVEL_MEGA && self::isBlacklistedLink($file_id)) {
                     throw new Exception_MegaCrypterLinkException(self::BLACKLISTED_LINK);
                 } else {
                     if ($extra) {
                         list($extra_info, $hide_name, $expire, $referer, $email, $zombie, $no_expire_token) = explode(self::SEPARATOR_EXTRA, $extra);
                         if (!$ignore_exceptions && !empty($expire) && time() >= $expire) {
                             throw new Exception_MegaCrypterLinkException(self::EXPIRED_LINK);
                         }
                         if (!empty($zombie) && $zombie != $_SERVER['REMOTE_ADDR']) {
                             throw new Exception_MegaCrypterLinkException(self::LINK_ERROR);
                         }
                     }
                     return ['file_id' => $file_id, 'file_key' => $file_key, 'extra_info' => !empty($extra_info) ? base64_decode($extra_info) : false, 'pass' => !empty($pass) ? $pass : false, 'auth' => !empty($auth) ? base64_decode($auth) : false, 'hide_name' => !empty($hide_name), 'expire' => !empty($expire) ? $expire : false, 'no_expire_token' => !empty($no_expire_token), 'referer' => !empty($referer) ? base64_decode($referer) : false, 'email' => !empty($email) ? base64_decode($email) : false, 'zombie' => !empty($zombie) ? $zombie : false, 'secret' => $secret];
                 }
             }
         }
     } else {
         throw new Exception_MegaCrypterLinkException(self::LINK_ERROR);
     }
 }
Exemple #2
0
 public static function decryptMegaDownloaderLinks($data)
 {
     return preg_replace_callback('/mega\\:\\/\\/(?P<folder>f)?(?P<enc>enc\\d*?)\\?(?P<linkdata>[\\da-z_,-]*?)(?=https?\\:|mega\\:|[^\\da-z_,-]|$)/i', function ($match) {
         $key = ['enc' => '6B316F36416C2D316B7A3F217A30357958585858585858585858585858585858', 'enc2' => 'ED1F4C200B35139806B260563B3D3876F011B4750F3A1A4A5EFD0BBE67554B44'];
         $iv = '79F10A01844A0B27FF5B2D4E0ED3163E';
         return Utils_MegaApi::MEGA_HOST . '/#' . strtoupper($match['folder']) . Utils_CryptTools::aesCbcDecrypt(Utils_MiscTools::urlBase64Decode($match['linkdata']), Utils_MiscTools::hex2bin($key[$match['enc']]), Utils_MiscTools::hex2bin($iv), true);
     }, $data);
 }
Exemple #3
0
 /**
  * Decrypts node attribute
  * 
  * @param string $at Base64 node encrypted attributes
  * @param string $key Base64 node key
  * @return string Json object
  * @throws Exception_MegaLinkException
  */
 private function _decryptAt($at, $key)
 {
     if (preg_match('/^.*MEGA.*?(?P<at>\\{.+\\}).*$/is', Utils_CryptTools::aesCbcDecrypt(Utils_MiscTools::urlBase64Decode($at), $this->_urlBase64KeyDecode($key)), $match)) {
         return $this->_sanitizeAt(json_decode($match['at']));
     } else {
         throw new Exception_MegaLinkException(self::EKEY);
     }
 }