Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
forgot_server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
data_server
forgot_server
Commits
7bd8b118
Commit
7bd8b118
authored
Mar 30, 2020
by
姜登
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
aes
parent
b05a63c8
Pipeline
#21177
passed with stage
in 2 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
task.js
app/controller/task.js
+6
-0
helper.js
app/extend/helper.js
+16
-0
No files found.
app/controller/task.js
View file @
7bd8b118
...
...
@@ -75,6 +75,12 @@ class TaskController extends Controller {
const
{
key
,
iv
}
=
config
.
aesParams
;
ctx
.
validate
(
this
.
submitRule
);
const
{
taskId
,
type
}
=
ctx
.
params
;
let
aeskey
=
taskId
+
ctx
.
request
.
body
.
timestamp
;
if
(
aeskey
.
length
<
16
)
{
while
(
aeskey
.
length
<
16
)
aeskey
+=
'0'
;
}
aeskey
=
aeskey
.
substring
(
0
,
16
);
ctx
.
request
.
body
=
ctx
.
helper
.
aesDecrypt
({
algorithm
:
'aes-128-ecb'
,
key
:
aeskey
,
data
:
ctx
.
request
.
body
.
data
});
const
data
=
JSON
.
parse
(
JSON
.
stringify
(
ctx
.
request
.
body
));
if
(
data
.
hasOwnProperty
(
'password'
))
{
data
.
password
=
ctx
.
helper
.
aescipher
(
'aes-128-cbc'
,
key
,
iv
,
data
.
password
);
...
...
app/extend/helper.js
View file @
7bd8b118
...
...
@@ -68,3 +68,18 @@ module.exports.aesdecipher = function(algorithm, key, iv, data) {
console
.
log
(
data
,
'UTF8 plaintext deciphered: '
+
cipherChunks
.
join
(
''
));
return
cipherChunks
.
join
(
''
);
};
module
.
exports
.
aesDecrypt
=
function
({
algorithm
,
key
,
data
,
iv
=
''
})
{
const
{
ctx
}
=
this
;
try
{
const
decipher
=
crypto
.
createDecipheriv
(
algorithm
,
key
,
iv
);
decipher
.
setAutoPadding
(
true
);
const
cipherChunks
=
[];
cipherChunks
.
push
(
decipher
.
update
(
data
,
'base64'
,
'utf8'
));
cipherChunks
.
push
(
decipher
.
final
(
'utf8'
));
return
cipherChunks
.
join
(
''
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'aesdecrupt_ERROR'
,
err
,
JSON
.
stringify
({
algorithm
,
key
,
data
,
iv
}));
ctx
.
throw
(
'参数解密有误'
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment