• 解析navicate数据库密码


     在线运行地址:代码在线运行 - 在线工具

    1. class NavicatPassword
    2. {
    3. protected $version = 0;
    4. protected $aesKey = 'libcckeylibcckey';
    5. protected $aesIv = 'libcciv libcciv ';
    6. protected $blowString = '3DC5CA39';
    7. protected $blowKey = null;
    8. protected $blowIv = null;
    9. public function __construct($version = 12)
    10. {
    11. $this->version = $version;
    12. $this->blowKey = sha1('3DC5CA39', true);
    13. $this->blowIv = hex2bin('d9c7c3c8870d64bd');
    14. }
    15. public function encrypt($string)
    16. {
    17. $result = FALSE;
    18. switch ($this->version) {
    19. case 11:
    20. $result = $this->encryptEleven($string);
    21. break;
    22. case 12:
    23. $result = $this->encryptTwelve($string);
    24. break;
    25. default:
    26. break;
    27. }
    28. return $result;
    29. }
    30. protected function encryptEleven($string)
    31. {
    32. $round = intval(floor(strlen($string) / 8));
    33. $leftLength = strlen($string) % 8;
    34. $result = '';
    35. $currentVector = $this->blowIv;
    36. for ($i = 0; $i < $round; $i++) {
    37. $temp = $this->encryptBlock($this->xorBytes(substr($string, 8 * $i, 8), $currentVector));
    38. $currentVector = $this->xorBytes($currentVector, $temp);
    39. $result .= $temp;
    40. }
    41. if ($leftLength) {
    42. $currentVector = $this->encryptBlock($currentVector);
    43. $result .= $this->xorBytes(substr($string, 8 * $i, $leftLength), $currentVector);
    44. }
    45. return strtoupper(bin2hex($result));
    46. }
    47. protected function encryptBlock($block)
    48. {
    49. return openssl_encrypt($block, 'BF-ECB', $this->blowKey, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING);
    50. }
    51. protected function decryptBlock($block)
    52. {
    53. return openssl_decrypt($block, 'BF-ECB', $this->blowKey, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING);
    54. }
    55. protected function xorBytes($str1, $str2)
    56. {
    57. $result = '';
    58. for ($i = 0; $i < strlen($str1); $i++) {
    59. $result .= chr(ord($str1[$i]) ^ ord($str2[$i]));
    60. }
    61. return $result;
    62. }
    63. protected function encryptTwelve($string)
    64. {
    65. $result = openssl_encrypt($string, 'AES-128-CBC', $this->aesKey, OPENSSL_RAW_DATA, $this->aesIv);
    66. return strtoupper(bin2hex($result));
    67. }
    68. public function decrypt($string)
    69. {
    70. $result = FALSE;
    71. switch ($this->version) {
    72. case 11:
    73. $result = $this->decryptEleven($string);
    74. break;
    75. case 12:
    76. $result = $this->decryptTwelve($string);
    77. break;
    78. default:
    79. break;
    80. }
    81. return $result;
    82. }
    83. protected function decryptEleven($upperString)
    84. {
    85. $string = hex2bin(strtolower($upperString));
    86. $round = intval(floor(strlen($string) / 8));
    87. $leftLength = strlen($string) % 8;
    88. $result = '';
    89. $currentVector = $this->blowIv;
    90. for ($i = 0; $i < $round; $i++) {
    91. $encryptedBlock = substr($string, 8 * $i, 8);
    92. $temp = $this->xorBytes($this->decryptBlock($encryptedBlock), $currentVector);
    93. $currentVector = $this->xorBytes($currentVector, $encryptedBlock);
    94. $result .= $temp;
    95. }
    96. if ($leftLength) {
    97. $currentVector = $this->encryptBlock($currentVector);
    98. $result .= $this->xorBytes(substr($string, 8 * $i, $leftLength), $currentVector);
    99. }
    100. return $result;
    101. }
    102. protected function decryptTwelve($upperString)
    103. {
    104. $string = hex2bin(strtolower($upperString));
    105. return openssl_decrypt($string, 'AES-128-CBC', $this->aesKey, OPENSSL_RAW_DATA, $this->aesIv);
    106. }
    107. };
    108. //需要指定版本两种,11或12
    109. //$navicatPassword = new NavicatPassword(11);
    110. //这里我指定的12的版本,原先指定的11,执行之后的密码是乱码
    111. $navicatPassword = new NavicatPassword(12);
    112. //解密
    113. //$decode = $navicatPassword->decrypt('5658213B');
    114. $decode = $navicatPassword->decrypt('复制出来的密码');
    115. echo $decode."\n";
    116. ?>

  • 相关阅读:
    第 2 章 线性表(线性表的动态分配顺序存储结构实现)
    从零开始实现VAE和CVAE
    栈与队列——用栈实现队列
    基于Spider的全站数据爬取
    GIS之深度学习10:运行Faster RCNN算法
    vim打开文件时执行命令
    Java的String类
    SwiftUI 内功之 如何提高 iOS 代码性能减少数组搜索优化
    3D人物建模用哪个软件入门比较快?
    http、https和Cookie
  • 原文地址:https://blog.csdn.net/u013008898/article/details/133749224