You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Greetings everyone, i am facing some issues with putting digital signatures on pdf files with using azure certificate vault. Problem appears when certificate is with non-exportable private key and have to rely on azure cryptography client. this is my current implementation:
asyncsignDocument(fileBuffer: Buffer,certName: string){try{Logger.log(`Starting document signing process for certificate: ${certName}...`);Logger.log(`Retrieving certificate: ${certName} from Azure...`);constcertificateData=awaitthis.certificateClient.getCertificate(certName);Logger.log('Extracting Key ID from the certificate...');constkeyId=certificateData.keyId;if(!keyId){Logger.error('Key ID not found in the certificate.');thrownewError('Key ID not found for certificate');}Logger.log(`Key ID found: ${keyId}`);Logger.log(`Creating CryptographyClient with Key ID: ${keyId}...`);constcryptoClient=newCryptographyClient(keyId,this.credential);Logger.log('CryptographyClient created successfully.');Logger.log('Loading and modifying PDF document...');constpdfDoc=awaitPDFDocument.load(fileBuffer);pdflibAddPlaceholder({pdfDoc: pdfDoc,reason: 'I am the author of this document',location: 'Lithuania',contactInfo: '[email protected]',name: 'Name Lastname',widgetRect: [50,100,250,150],});constpdfWithPlaceholderBytes=awaitpdfDoc.save();constdocumentHash=this.createHashWith(Buffer.from(pdfWithPlaceholderBytes));constsignResult: SignResult=awaitcryptoClient.sign("RS256",documentHash);constazureSigner=newAzureVaultSigner(signResult.result);constsignedPdfBytes=awaitSignPdf.sign(pdfWithPlaceholderBytes,azureSigner);Logger.log('Signature injected into PDF document successfully.');fs.writeFileSync('output-signed.pdf',signedPdfBytes);returnsignedPdfBytes;}catch(error){Logger.error('Error signing document:',error.message);thrownewError(`Error signing document: ${error.message}`);}}privatecreateHashWith(buffer: Buffer): Buffer{consthash=createHash('sha256');hash.update(buffer);returnhash.digest();}
import{Signer}from'@signpdf/signpdf'classAzureVaultSignerextendsSigner{signature: Buffer;constructor(signature: any){super();this.signature=Buffer.from(signature);;// Store the signature}asyncsign(pdfBuffer,signingTime){returnpdfBuffer;}}exportdefaultAzureVaultSigner;
as i understand, Azures cryptoclient sign returns the signature it self, that later has to be injected in to original pdf. And i believe that issue is in my custom signer. and after running the api im getting this
The text was updated successfully, but these errors were encountered:
import{Signer}from'@signpdf/signpdf'classAzureVaultSignerextendsSigner{signature: Buffer;constructor(signature: any){super();this.signature=Buffer.from(signature);;// Store the signature}asyncsign(pdfBuffer,signingTime){returnpdfBuffer;}}exportdefaultAzureVaultSigner;
You're just returning the PDF in your signer and not the signature. If you change that, it may work
import{Signer}from'@signpdf/signpdf'classAzureVaultSignerextendsSigner{signature: Buffer;constructor(signature: any){super();this.signature=Buffer.from(signature);;// Store the signature}asyncsign(pdfBuffer,signingTime){returnpdfBuffer;}}exportdefaultAzureVaultSigner;
You're just returning the PDF in your signer and not the signature. If you change that, it may work
Maybe you have idea where i could fine example of custom signer that would work with my issue?
Greetings everyone, i am facing some issues with putting digital signatures on pdf files with using azure certificate vault. Problem appears when certificate is with non-exportable private key and have to rely on azure cryptography client. this is my current implementation:
as i understand, Azure
s cryptoclient sign returns the signature it self, that later has to be injected in to original pdf. And i believe that issue is in my custom signer. and after running the api i
m getting thisThe text was updated successfully, but these errors were encountered: