admin管理员组文章数量:1292146
` I am getting the error "Private key is required to compute signature" even though the private key is being read correctly from the file and logged. I have tried both PKCS1 and PKCS8 private key formats but the issue persists.
const privateKey = await fs.promises.readFile('./src/services/SDI-PKCS8-04126420043.pem', 'utf8');
// Validate private key format
if (!privateKey.includes('BEGIN PRIVATE KEY') && !privateKey.includes('BEGIN RSA PRIVATE KEY')) {
throw new Error('Invalid Private Key format');
}
// Read certificate file
const certificate = await fs.promises.readFile('./src/services/SDI-04126420043.pem', 'utf8');
// Initialize signature
const sig = new SignedXml({
canonicalizationAlgorithm: '',
signatureAlgorithm: '',
});
// Assign keyInfoProvider and signingKey
sig.keyInfoProvider = new MyKeyInfo(privateKey, certificate);
sig.signingKey = Buffer.from(privateKey.trim(), 'utf8');
// Add reference to XML document
sig.addReference({
xpath: "/*",
transforms: [";],
digestAlgorithm: ";
});
// Compute signature
sigputeSignature(xml);
// Get signed XML
const signedXml = sig.getSignedXml();
本文标签: nodejsHeading Private Key Error in XML Signature ComputationStack Overflow
版权声明:本文标题:node.js - Heading: Private Key Error in XML Signature Computation - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741551266a2384893.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论