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);
 }
 protected function action()
 {
     if ($this->isValidReferer()) {
         $mc_links = Utils_MegaCrypter::encryptLinkList(Utils_MiscTools::extractLinks(Utils_CryptTools::decryptMegaDownloaderLinks($this->request->getPostVar('links'))), ['tiny_url' => $this->request->getPostVar('tiny_url'), 'pass' => $this->request->getPostVar('pass'), 'extra_info' => $this->request->getPostVar('extra_info'), 'hide_name' => $this->request->getPostVar('hide_name'), 'expire' => $this->request->getPostVar('expire'), 'no_expire_token' => $this->request->getPostVar('no_expire_token'), 'referer' => $this->request->getPostVar('referer'), 'email' => $this->request->getPostVar('email')], $this->request->getPostVar('app_finfo'));
         if (!empty($mc_links)) {
             $this->setViewData(['links' => Utils_MiscTools::rimplode("\r\n", $mc_links), 'cols' => min([Utils_MiscTools::getMaxStringLength($mc_links), self::CRYPT_TEXTAREA_COLS]), 'tot_links' => Utils_MiscTools::rCount($mc_links)]);
         } else {
             throw new Exception(__METHOD__ . ' No links could be crypted!');
         }
     } else {
         throw new Exception_InvalidRefererException(function (Controller_DefaultController $controller) {
             $controller->redirect('/');
         });
     }
 }
 private function _encryptApiField($field_value, $pass_sha256, $iv)
 {
     return base64_encode(Utils_CryptTools::aesCbcEncrypt($field_value, $pass_sha256, $iv, true));
 }
Exemple #5
0
 /**
  * Decrypts node key
  * 
  * @param string $node_key Base64 encrypted node key
  * @param string $folder_key Base64 master key
  * @return string Base64 node key
  */
 private function _decryptB64NodeKey($node_key, $folder_key)
 {
     return Utils_MiscTools::urlBase64Encode(Utils_CryptTools::aesEcbDecrypt(Utils_MiscTools::urlBase64Decode($node_key), $this->_urlBase64KeyDecode($folder_key)));
 }