Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 55e3f92

Browse files
committed
add: AES/ECB/PKCS5Padding encryption algorithm
1 parent 612e24f commit 55e3f92

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

‎laravel/app/Helper/functions.php‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,29 @@ function humpToLine($str)
109109
}, $str);
110110
return $str;
111111
}
112+
113+
/**
114+
* 加密算法: AES/ECB/PKCS5Padding
115+
* @param $aesKey
116+
* @param $data
117+
* @param string $iv
118+
* @return string
119+
*/
120+
function encrypt($aesKey, $data, $iv = '')
121+
{
122+
$encrypted = openssl_encrypt($data, 'aes-128-ecb', $aesKey, OPENSSL_RAW_DATA, $iv);
123+
return base64_encode($encrypted);
124+
}
125+
126+
/**
127+
* 解密算法: AES/ECB/PKCS5Padding
128+
* @param $aesKey
129+
* @param $data
130+
* @param string $iv
131+
* @return false|string
132+
*/
133+
function decrypt($aesKey, $data, $iv = '')
134+
{
135+
$encrypted = base64_decode($data);
136+
return openssl_decrypt($encrypted, 'aes-128-ecb', $aesKey, OPENSSL_RAW_DATA, $iv);
137+
}

‎laravel/app/Http/Repository/ToolRepository.php‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,23 @@ public function hexToString($input)
7575
*/
7676
public function openidSecret($input)
7777
{
78-
return substr(md5($input), 0, 16);
78+
$params = explode("\n", $input);
79+
$aesKey = substr(md5($params[0]), 0, 16);
80+
switch (count($params)) {
81+
case 2:
82+
parse_str($params[1], $query);
83+
$encrypt = '';
84+
foreach ($query as $key => $value) {
85+
$encrypt .= '&'.$key.'='.encrypt($aesKey, $value);
86+
}
87+
$encrypt = trim($encrypt, '&');
88+
break;
89+
case 1:
90+
default:
91+
return $aesKey;
92+
break;
93+
}
94+
return $aesKey."\n".$encrypt;
7995
}
8096

8197
/**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /