Warm tip: This article is reproduced from serverfault.com, please click

How to encrypt & decrypt amazon seller api report document using nodejs

发布于 2020-12-08 19:33:39

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

response

{ "payload": { "reportDocumentId": "amzn1.tortuga.3.18666cbf-dfdf-dsfsd-bf4b-sdfdsfsdfsdf.TBWRJF481G44N", "encryptionDetails": { "standard": "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=host&X-Amz-Expires=300&X-Amz-Credential=dscfdsfsdfsdfdsfsdf%2F20201208%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Signature=45hjkkjkjdfdsfsd4545jkkjhkj4554j" } }


decryption nodejs code


const crypto = require('crypto');

const algorithm = 'AES';

const key = '9CT0qwtzUHLXlFTh0aLxk4qSQYAJ7texG8KDIZ0JSy8='; const iv = 'nG2rSrj1Ra9e03IStEBkdg==';

const decipher = crypto.createDecipheriv(algorithm, key, iv);


Error - Invalid IV length


Questioner
ROHIT THAKUR
Viewed
0
1,002 2020-12-21 18:08:05

No idea about node js but I have implemented this API in PHP and it works for me. This might be helpful for you.

$key = base64_decode('xxxxx');
$iv = base64_decode('xxxxxx');
$decryptedData = openssl_decrypt(file_get_contents($url), 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);