Skip to content

Commit 3769576

Browse files
committed
update deps & use openssl functions
1 parent 681353f commit 3769576

File tree

3 files changed

+18
-29
lines changed

3 files changed

+18
-29
lines changed

.travis.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
sudo: false
22
language: php
33
php:
4-
- '5.4'
54
- '5.6'
65
- '7.0'
6+
- '7.1'
7+
- '7.2'
78
language: node_js
89
node_js:
9-
- 7
10-
- 8
10+
- "7"
11+
- "8"
12+
- "9"
13+
- "10"
1114
cache:
1215
directories:
1316
- node_modules

package.json

+10-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"lint": "eslint index.js lib test",
88
"fix": "npm run lint -- --fix",
99
"test": "npm run lint && jest --forceExit",
10-
"test-cov": "npm run test -- --coverage"
10+
"test-cov": "npm run test -- --detectOpenHandles"
1111
},
1212
"keywords": [],
1313
"author": "Runrioter Wung <[email protected]>",
@@ -17,14 +17,17 @@
1717
"index.js"
1818
],
1919
"devDependencies": {
20-
"eslint": "^4.19.1",
21-
"eslint-config-egg": "^7.0.0",
22-
"eslint-plugin-jest": "^21.15.2",
23-
"jest": "^22.4.4"
20+
"eslint": "^5.6.0",
21+
"eslint-config-egg": "^7.1.0",
22+
"eslint-plugin-jest": "^21.22.0",
23+
"jest": "^23.6.0"
2424
},
2525
"dependencies": {
26-
"debug": "^3.1.0",
26+
"debug": "^4.0.1",
2727
"iconv-lite": "^0.4.23",
28-
"strong-soap": "^1.9.0"
28+
"strong-soap": "^1.13.0"
29+
},
30+
"jest": {
31+
"testEnvironment": "node"
2932
}
3033
}

test/crypto.php

+2-19
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,14 @@
2525
}
2626

2727
function encrypt($str, $key , $iv) {
28-
$block_size = mcrypt_get_block_size(MCRYPT_DES, MCRYPT_MODE_CBC);
2928
$str = mb_convert_encoding($str, 'GBK', 'UTF-8');
30-
$str = pkcs_pad($str, $block_size);
31-
$data = mcrypt_encrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_CBC, $iv);
29+
$data = openssl_encrypt($str, 'DES-CBC', $key, OPENSSL_RAW_DATA, $iv);
3230
return base64_encode($data);
3331
}
3432

35-
function pkcs_pad($str, $block_size) {
36-
$pad = $block_size - (strlen($str) % $block_size);
37-
return $str . str_repeat(chr($pad), $pad);
38-
}
39-
4033
function decrypt($str, $key, $iv) {
4134
$data = base64_decode($str);
42-
$str = mcrypt_decrypt(MCRYPT_DES, $key, $data, MCRYPT_MODE_CBC, $iv);
43-
$str = pkcs_unpad($str);
35+
$str = openssl_decrypt($data, 'DES-CBC', $key, OPENSSL_RAW_DATA, $iv);
4436
$str = mb_convert_encoding($str, 'UTF-8', 'GBK');
4537
return $str;
4638
}
47-
48-
function pkcs_unpad($str) {
49-
$pad = ord(substr($str, -1));
50-
if ($pad > strlen($str)) return false;
51-
if (strspn($str, chr($pad), strlen($str) - $pad) !== $pad) {
52-
return false;
53-
}
54-
return substr($str, 0, -1 * $pad);
55-
}

0 commit comments

Comments
 (0)