Load an XML File from the File Cabinet and Sign It Using a Digital Certificate

The following sample loads an XML file from the File Cabinet and signs it using the digital certificate with internal ID ‘custcertificate1’. Note that this sample uses a hard-coded value for the file id. You should change this value to a valid file id from your account.

Note:

This sample script uses the require function so that you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.

Important:

This sample uses SuiteScript 2.1. For more information, see SuiteScript 2.1.

          /**
 * @NApiVersion 2.1
 */

require(['N/crypto/certificate','N/file'],(cert, file) => {
    // Load the file from the File Cabinet.
    // Note that the id value is hard-coded in this sample, and you should use
    // a valid file id from your account.
    let infNFe = file.load({
        id: 922
    });
    let signedXml = cert.signXml({
        algorithm: certificate.HashAlg.SHA256,
        certId: 'custcertificate1',
        rootTag: 'infNFe',
        xmlString: infNFe.getContents()
    });
    cert.verifyXMLSignature({
        signedXml:signedXml,
        rootTag: 'infNFe'
    });
});// Note that this value is hard-coded in this sample, and you should use 

        

General Notices