const crypto = require('crypto'); const fs = require('fs'); //Calculate the signature of the test.txt file. //const buffer = fs.readFileSync('test.txt'); //Calculate the signature of the string "your content 12345". const buffer = Buffer.from('your content 12345', 'utf8'); // The content of the private key used for encryption should be... //-----BEGIN RSA PRIVATE KEY----- // Private key content. //-----END RSA PRIVATE KEY----- // Read the private key. const privateKey = fs.readFileSync('mytproof.key'); // Convert the private key to KeyObject. const keyObject = crypto.createPrivateKey(privateKey); // Sign the buffer using the private key. const signature = crypto.sign('sha256', buffer, { key: keyObject, padding: crypto.constants.RSA_PKCS1_PADDING }); // Display the obtained signature value (displayed in hex format with 512 characters) console.log(signature.toString('hex'));