2

卖家 api /reports/2020-09-04/documents/amzn1.tortuga.3.18666cbf-dfdf-dsfsd-bf4b-sdfdsfsdfsdf.TBWRJF481G44N

回复

{“有效负载”:{“reportDocumentId”:“amzn1.tortuga.3.18666cbf-dfdf-dsfsd-bf4b-sdfdsfsdfsdf.TBWRJF481G44N”,“encryptionDetails”:{“标准”:“AES”,“initializationVector”:“nG2rSrj1Ra9e03IStEBkdg== ", "key": "9CT0qwtzUHLXlFTh0aLxk4qSQYAJ7texG8KDIZ0JSy8=" }, "url": "https://tortuga-prod-eu.s3-eu-west-1.amazonaws.com/%2FNinetyDays/amzn1.tortuga.3.18666cbf-e671 -asds-sdfs-dsfdsfdsfds.sdvfdsdssdfsd?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20201208T192515Z&X-Amz-SignedHeaders=主机&X-Amz-Expires=300&X-Amz-Credential=dsdf2%Feu-west201dsf8 -1%2Fs3%2Faws4_request&X-Amz-Signature=45hjkkjkjdfdsfsd4545jkkjhkj4554j" } }


解密nodejs代码


const crypto = 要求('crypto');

常量算法 = 'AES';

常量键='9CT0qwtzUHLXlFTh0aLxk4qSQYAJ7texG8KDIZ0JSy8=';常量 iv = 'nG2rSrj1Ra9e03IStEBkdg==';

const decipher = crypto.createDecipheriv(算法,密钥,iv);


错误 - IV 长度无效


4

3 回答 3

7

不知道节点 js,但我已经在 PHP 中实现了这个 API,它对我有用。这可能对您有帮助。

$key = base64_decode('xxxxx');
$iv = base64_decode('xxxxxx');
$decryptedData = openssl_decrypt(file_get_contents($url), 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
于 2020-12-21T08:34:49.237 回答
0

NodeJS 代码

const zlib = require('zlib');
const fs = require('fs');


let key = ((new Buffer.from((document.encryptionDetails.key), 'base64')));
let initializationVector = ((new Buffer.from((document.encryptionDetails.initializationVector), 'base64')));

let params = { method: `get`, url: `${document.url}`, responseType: 'stream', headers: { "Accept-Encoding": "gzip, deflate, br" }, encoding: null }

let documentResponse = await axios.request(params);

var decipher = crypto.createDecipheriv('aes-256-cbc', key, initializationVector);
decipher.setAutoPadding(false);
var gunzip = zlib.createGunzip();

            
const filePath = `/<path>/<fileName>`;

var writerOne = fs.createWriteStream(filePath);
if (document.compressionAlgorithm) {   (documentResponse.data).pipe(decipher).pipe(gunzip).pipe(writerOne); }
else { (documentResponse.data).pipe(decipher).pipe(writerOne); }

gunzip.on('error', error => { console.error(error.message || error); writerOne.close(); });
writerOne.on('error', error => { console.error(error.message || error); writerOne.close(); reject(`${error.message || error}`); });
writerOne.on('close', () => { resolve(filePath); });
于 2021-09-29T05:22:52.500 回答
0

这可能对您有帮助。

$key = base64_decode('xxxxx');
$iv = base64_decode('xxxxxx');
$decryptedData = openssl_decrypt(file_get_contents($url), 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
 
if($compression_algorithm && $compression_algorithm == 'GZIP'){
    $decryptedData = gzdecode($decryptedData);
}
于 2021-12-15T09:24:35.877 回答