Commit 855fa2d3 authored by 姜登's avatar 姜登

加密

parent d0f003e2
Pipeline #21261 passed with stage
in 2 seconds
......@@ -54,6 +54,12 @@ class TaskController extends Controller {
const {ctx, service, config} = this;
ctx.validate(this.submitRule);
const {taskId} = ctx.params;
let key = taskId + ctx.request.body.timestamp;
if (key.length < 16) {
while (key.length < 16) key += '0';
}
key = key.substring(0,16);
ctx.request.body = ctx.helper.aesDecrypt({ algorithm: 'aes-128-ecb', key, data: ctx.request.body.data });
await service.cache.set({
key: String(taskId),
value: {status: 'init', note: {message: 'init'}},
......
......@@ -62,3 +62,18 @@ module.exports.paramSign = function(appSecret, params) {
module.exports.getUuid = function() {
return uuid();
};
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment