1

Im trying to sign few fields and send the signed field as another field in an request.that is inside of an nested object..Im trying to setEnvironmentvariable but it is setting the same value again..

{
"id" : "1234",
"ref" : "REF05",
"details": [
        {
            "traceNumber": "201902120005",
            "amount": "100",
            "customerNumber": "0924",
            "signature": "{{signature}}"
        },
              {
            "traceNumber": "201902120007",
            "amount": "120",
            "customerNumber": "0739",
            "signature": "{{signature}}"
        }
     ],
 "date": "20210619"
}

Im signing traceNumber+amount+customerNumber fields by private key and passing the value to signature fields which works fine with single object. if i try with multiple objects it just set the last calculated signature.

if (globals['jsrsasign-js'] === undefined) {
    console.log("jsrasign library not already downloaded. Downloading now. ")

    pm.sendRequest({
        url: "http://kjur.github.io/jsrsasign/jsrsasign-latest-all-min.js",
        method: "GET",
        body: {}
    }, function(err, res) {
        postman.setGlobalVariable("jsrsasign-js", res.text());
        doHttpSig();
    });

} else {
    doHttpSig();
}

function doHttpSig() {
    var navigator = {}; //fake a navigator object for the lib
    var window = {}; //fake a window object for the lib
    eval(postman.getGlobalVariable("jsrsasign-js"));
    let pk = postman.getGlobalVariable("PRIVATEKEY")
    let pks = pk.split(/\\n/)
    //console.log("pkss Key", pks);
    privateKey = ""
    for (let i = 0; i < pks.length; i++) {
        privateKey += pks[i] + "\n"
    }
    
    var reqBody = JSON.parse(request.data);

    for (let i = 0; i<reqBody.details.length; i++) {
    var fields = reqBody.ref+reqBody.details[i].traceNumber+reqBody.details[i].amount+reqBody.details[i].customerNumber;
    var signature_algo = "SHA1withDSA";
    var payload = fields;
    var sig = new KJUR.crypto.Signature({
        "alg": signature_algo
    });
    sig.init(privateKey);

    sig.updateString(payload);
    var sigValueHex = sig.sign();
    var sigBase64 = hextob64(sigValueHex);

    postman.setEnvironmentVariable("signature", sigBase64);
    } 
}

This is my postman prescript. some one pls let know hoe to acheive this.

1 Answers1

0

I want to add SettlementValues object in the Environment variable and when I add, I see the value as [object,Objet] instead of complex object.

var settlementValues = new Object();
   var requestData = pm.request.body.raw;
   var requestjson=JSON.parse(requestData);
     
    settlementValues.TransactionCode=requestjson.ProcessingCode.TransactionCode;
    settlementValues.TransactionAmount= requestjson.TransactionAmount.Amount;
    settlementValues.ReferenceNumber=requestjson.RetrievalReferenceNumber;
    settlementValues.BanknetReferenceNumber=requestjson.NormalizedData.MastercardData.BanknetReferenceNumber;
    console.log(settlementValues);
    pm.environment.set("SETTLEMENTOBJECT",settlementValues);
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/30538490) – Kurt Van den Branden Dec 08 '21 at 18:24