Hash SHA256

SOLVED

Hello,

I'm writing a script to get results from a REST API.

To run this script, i have to put a header that is encrypted in sha256

Is there any method implemented in SageX3 to hash my content in sha256?

Thanks

Parents
  • 0

    We use node.js for that, you execute it from inside 4GL, but it is much easier to do it in a global language like js. We did this for the Angolan Legislation, if you need we can share this know how. Cheers.

  • 0 in reply to Martins de Almeida

    Hi, I finnaly started to develop the function with the base I found in Sage X3 Help on the Crypto bundle.
    I changed a bit the code to encrypt in SHA256:

    "use strict";
    
    var crypto = require('crypto');
    
    // computes hash in SHA256 digest, returns it as a hex string.
    exports.digestsha256(text) {
    var hash = crypto.createHash('sha256');
    hash.update(text, 'utf8');
    return hash.digest('hex');
    }

    But, when i run the X3 script

    STATUSCODE = func ASYRWEBSER.EXEC_JS("bundles/yeth-crypto/lib/crypto-helper", "digestsha256", "sync", '"helloworld"', "0", 0, "", "0", RESHEAD, RESBODY)

    The STATUSCODE is always 500, and I don't have 

    Have you any clue on that problem?

    Thanks

Reply
  • 0 in reply to Martins de Almeida

    Hi, I finnaly started to develop the function with the base I found in Sage X3 Help on the Crypto bundle.
    I changed a bit the code to encrypt in SHA256:

    "use strict";
    
    var crypto = require('crypto');
    
    // computes hash in SHA256 digest, returns it as a hex string.
    exports.digestsha256(text) {
    var hash = crypto.createHash('sha256');
    hash.update(text, 'utf8');
    return hash.digest('hex');
    }

    But, when i run the X3 script

    STATUSCODE = func ASYRWEBSER.EXEC_JS("bundles/yeth-crypto/lib/crypto-helper", "digestsha256", "sync", '"helloworld"', "0", 0, "", "0", RESHEAD, RESBODY)

    The STATUSCODE is always 500, and I don't have 

    Have you any clue on that problem?

    Thanks

Children
  • +1 in reply to SERVAES
    verified answer

    I found the solution,
    The sample in X3 help doesn't work as it is.

    but with the keyword function, it's OK

    "use strict";
    
    var crypto = require('crypto');
    
    // computes hash in SHA256 digest, returns it as a hex string.
    exports.digestsha256 = function(text) {
        var hash = crypto.createHash('sha256');
        hash.update(text, 'utf8');
        return hash.digest('hex');
    }