{"id":1138,"date":"2018-12-24T21:51:33","date_gmt":"2018-12-24T13:51:33","guid":{"rendered":"http:\/\/www.luwl.net\/?p=1138"},"modified":"2018-12-24T21:57:42","modified_gmt":"2018-12-24T13:57:42","slug":"navicat%e5%af%86%e7%a0%81%e7%9a%84%e7%a0%b4%e8%a7%a3","status":"publish","type":"post","link":"http:\/\/www.luwl.net\/?p=1138","title":{"rendered":"navicat\u5bc6\u7801\u7684\u7834\u89e3"},"content":{"rendered":"\r\n<p>Navicat\u662f\u4e00\u6b3e\u6570\u636e\u5e93\u7ba1\u7406\u8f6f\u4ef6\uff0c\u5176\u4fdd\u5b58\u7684\u8fde\u63a5\u5bc6\u7801\u662f\u52a0\u5bc6\u7684\uff0c\u5982\u679c\u8fd8\u53ef\u4ee5\u8fde\u63a5\uff0c\u4f46\u662f\u5fd8\u8bb0\u4e86\u5bc6\u7801\uff0c\u901a\u8fc7\u7834\u89e3\u5176\u4fdd\u5b58\u7684\u52a0\u5bc6\u5bc6\u7801\u662f\u53ef\u4ee5\u7684\u3002\u6709\u4eba\u505a\u4e86\u5c0f\u8f6f\u4ef6\uff0c\u4f46\u8fd9\u4e2a\u662fphp\u7248\u672c\u7684\uff0c\u6211\u60f3\u5e94\u8be5\u66f4\u65b9\u4fbf\u5427\u3002<\/p>\r\n\r\n\r\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\nclass NavicatPassword\r\n{\r\n    protected $version = 0;\r\n    protected $aesKey = 'libcckeylibcckey';\r\n    protected $aesIv = 'libcciv libcciv ';\r\n    protected $blowString = '3DC5CA39';\r\n    protected $blowKey = null;\r\n    protected $blowIv = null;\r\n    public function __construct($version = 12)\r\n    {\r\n        $this-&gt;version = $version;\r\n        $this-&gt;blowKey = sha1('3DC5CA39', true);\r\n        $this-&gt;blowIv = hex2bin('d9c7c3c8870d64bd');\r\n    }\r\n    \r\n    public function encrypt($string)\r\n    {\r\n        $result = FALSE;\r\n        switch ($this-&gt;version) {\r\n            case 11:\r\n                $result = $this-&gt;encryptEleven($string);\r\n                break;\r\n            case 12:\r\n                $result = $this-&gt;encryptTwelve($string);\r\n                break;\r\n            default:\r\n                break;\r\n        }\r\n        \r\n        return $result;\r\n    }\r\n    protected function encryptEleven($string)\r\n    {\r\n        $round = intval(floor(strlen($string) \/ 8));\r\n        $leftLength = strlen($string) % 8;\r\n        $result = '';\r\n        $currentVector = $this-&gt;blowIv;\r\n        \r\n        for ($i = 0; $i &lt; $round; $i++) {\r\n            $temp = $this-&gt;encryptBlock($this-&gt;xorBytes(substr($string, 8 * $i, 8), $currentVector));\r\n            $currentVector = $this-&gt;xorBytes($currentVector, $temp);\r\n            $result .= $temp;\r\n        }\r\n        \r\n        if ($leftLength) {\r\n            $currentVector = $this-&gt;encryptBlock($currentVector);\r\n            $result .= $this-&gt;xorBytes(substr($string, 8 * $i, $leftLength), $currentVector);\r\n        }\r\n        \r\n        return strtoupper(bin2hex($result));\r\n    }\r\n    protected function encryptBlock($block)\r\n    {\r\n        return openssl_encrypt($block, 'BF-ECB', $this-&gt;blowKey, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING); \r\n    }\r\n    protected function decryptBlock($block)\r\n    {\r\n        return openssl_decrypt($block, 'BF-ECB', $this-&gt;blowKey, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING); \r\n    }\r\n    protected function xorBytes($str1, $str2)\r\n    {\r\n        $result = '';\r\n        for ($i = 0; $i &lt; strlen($str1); $i++) {\r\n            $result .= chr(ord($str1&#x5B;$i]) ^ ord($str2&#x5B;$i]));\r\n        }\r\n        \r\n        return $result;\r\n    }\r\n    protected function encryptTwelve($string)\r\n    {\r\n        $result = openssl_encrypt($string, 'AES-128-CBC', $this-&gt;aesKey, OPENSSL_RAW_DATA, $this-&gt;aesIv);\r\n        return strtoupper(bin2hex($result));\r\n    }\r\n    public function decrypt($string)\r\n    {\r\n        $result = FALSE;\r\n        switch ($this-&gt;version) {\r\n            case 11:\r\n                $result = $this-&gt;decryptEleven($string);\r\n                break;\r\n            case 12:\r\n                $result = $this-&gt;decryptTwelve($string);\r\n                break;\r\n            default:\r\n                break;\r\n        }\r\n        \r\n        return $result;\r\n    }\r\n    protected function decryptEleven($upperString)\r\n    {\r\n        $string = hex2bin(strtolower($upperString));\r\n        \r\n        $round = intval(floor(strlen($string) \/ 8));\r\n        $leftLength = strlen($string) % 8;\r\n        $result = '';\r\n        $currentVector = $this-&gt;blowIv;\r\n        \r\n        for ($i = 0; $i &lt; $round; $i++) {\r\n            $encryptedBlock = substr($string, 8 * $i, 8);\r\n            $temp = $this-&gt;xorBytes($this-&gt;decryptBlock($encryptedBlock), $currentVector);\r\n            $currentVector = $this-&gt;xorBytes($currentVector, $encryptedBlock);\r\n            $result .= $temp;\r\n        }\r\n        \r\n        if ($leftLength) {\r\n            $currentVector = $this-&gt;encryptBlock($currentVector);\r\n            $result .= $this-&gt;xorBytes(substr($string, 8 * $i, $leftLength), $currentVector);\r\n        }\r\n        \r\n        return $result;\r\n    }\r\n    protected function decryptTwelve($upperString)\r\n    {\r\n        $string = hex2bin(strtolower($upperString));\r\n        return openssl_decrypt($string, 'AES-128-CBC', $this-&gt;aesKey, OPENSSL_RAW_DATA, $this-&gt;aesIv);\r\n    }\r\n}\r\n$navicatPassword = new NavicatPassword(11);\/\/\u652f\u630111\u53ca12\u7248\u672c\r\n$encode = $navicatPassword-&gt;encrypt('yxbl'); \r\necho $encode;\r\n$decode = $navicatPassword-&gt;decrypt($encode);\r\necho $decode;\r\n?&gt;\r\n\r\n    \r\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Navicat\u662f\u4e00\u6b3e\u6570\u636e\u5e93\u7ba1\u7406\u8f6f\u4ef6\uff0c\u5176\u4fdd\u5b58\u7684\u8fde\u63a5\u5bc6\u7801\u662f\u52a0\u5bc6\u7684\uff0c\u5982\u679c\u8fd8\u53ef\u4ee5\u8fde\u63a5\uff0c\u4f46 &hellip; <a href=\"http:\/\/www.luwl.net\/?p=1138\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1138","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.luwl.net\/index.php?rest_route=\/wp\/v2\/posts\/1138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.luwl.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.luwl.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.luwl.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.luwl.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1138"}],"version-history":[{"count":3,"href":"http:\/\/www.luwl.net\/index.php?rest_route=\/wp\/v2\/posts\/1138\/revisions"}],"predecessor-version":[{"id":1141,"href":"http:\/\/www.luwl.net\/index.php?rest_route=\/wp\/v2\/posts\/1138\/revisions\/1141"}],"wp:attachment":[{"href":"http:\/\/www.luwl.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.luwl.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1138"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.luwl.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}