提交 06de0369 编写于 作者: T tianhe1986

版本12密码处理。

Signed-off-by: Ntianhe1986 <w1s2j3229@163.com>
上级 696f24a2
......@@ -4,9 +4,11 @@ namespace FatSmallTools;
class NavicatPassword
{
protected $version = 11;
protected $version = 0;
protected $aesKey = 'libcckeylibcckey';
protected $aesIv = 'libcciv libcciv ';
public function __construct($version = 11)
public function __construct($version = 12)
{
$this->version = $version;
}
......@@ -34,9 +36,10 @@ class NavicatPassword
}
protected function encryptTwelve($string)
{
$result = openssl_encrypt($string, 'AES-128-CBC', $this->aesKey, OPENSSL_RAW_DATA, $this->aesIv);
return strtoupper(bin2hex($result));
}
public function decrypt($string)
{
$result = FALSE;
......@@ -60,6 +63,7 @@ class NavicatPassword
}
protected function decryptTwelve($string)
{
$data = hex2bin(strtolower($string));
return openssl_decrypt($data, 'AES-128-CBC', $this->aesKey, OPENSSL_RAW_DATA, $this->aesIv);
}
}
\ No newline at end of file
......@@ -7,5 +7,13 @@ use FatSmallTools\NavicatPassword;
class NavicatPasswordTest extends TestCase
{
public function testHandleTwelve()
{
$navicatPassword = new NavicatPassword(12);
$string = '123456';
$encrypted = $navicatPassword->encrypt($string);
$this->assertEquals('833E4ABBC56C89041A9070F043641E3B', $encrypted);
$decrypted = $navicatPassword->decrypt($encrypted);
$this->assertEquals($string, $decrypted);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册