You need to sign in to do that
Don't have an account?
Anoop Krish Kuniyil
Attach digital signature to PDF document
Hi All
We have requirement to add digial signature authrozied by CA in PDF to ensure the security of the document send in email.
I have created Apex class and Apex page to implement this functionality. I am not sure how to attach the signature created by Crypto.sign method in pdf document. Can anyone help me to attach certificate to PDF document?
Apex class:
public class CryptoSign {
public static void generateCryptoSign(){
PageReference pageRef = Page.ApexCryptoTest;
Blob pdfDoc = pageRef.getContentAsPDF();
String algorithmName = 'RSA-SHA1';
String key = 'PKCS12 Key';
Blob privateKey = EncodingUtil.base64Decode(key);
// Using Crypto.sign PDF document generated from Apex page is digital signing
Blob pdfDocSigned = Crypto.sign(algorithmName, pdfDoc, privateKey);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setSubject('Email Subject');
mail.setHtmlBody('Email with Signed PDF attachment');
List<String> toAddr = new List<String>();
toAddr.add('test@test.com');
mail.setToAddresses(toAddr);
List<Messaging.Emailfileattachment> attachments = new List<Messaging.Emailfileattachment>();
Messaging.Emailfileattachment attach = new Messaging.Emailfileattachment();
attach = new Messaging.Emailfileattachment();
attach.setFileName('SignedPDF.pdf');
attach.setBody(pdfDocSigned);
attachments.add(attach);
mail.setFileAttachments(attachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Apex Page:
<apex:page >
Test Apex page
</apex:page>
We have requirement to add digial signature authrozied by CA in PDF to ensure the security of the document send in email.
I have created Apex class and Apex page to implement this functionality. I am not sure how to attach the signature created by Crypto.sign method in pdf document. Can anyone help me to attach certificate to PDF document?
Apex class:
public class CryptoSign {
public static void generateCryptoSign(){
PageReference pageRef = Page.ApexCryptoTest;
Blob pdfDoc = pageRef.getContentAsPDF();
String algorithmName = 'RSA-SHA1';
String key = 'PKCS12 Key';
Blob privateKey = EncodingUtil.base64Decode(key);
// Using Crypto.sign PDF document generated from Apex page is digital signing
Blob pdfDocSigned = Crypto.sign(algorithmName, pdfDoc, privateKey);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setSubject('Email Subject');
mail.setHtmlBody('Email with Signed PDF attachment');
List<String> toAddr = new List<String>();
toAddr.add('test@test.com');
mail.setToAddresses(toAddr);
List<Messaging.Emailfileattachment> attachments = new List<Messaging.Emailfileattachment>();
Messaging.Emailfileattachment attach = new Messaging.Emailfileattachment();
attach = new Messaging.Emailfileattachment();
attach.setFileName('SignedPDF.pdf');
attach.setBody(pdfDocSigned);
attachments.add(attach);
mail.setFileAttachments(attachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Apex Page:
<apex:page >
Test Apex page
</apex:page>
May I suggest you please check the below link for reference.
- https://success.salesforce.com/answers?id=9063A000000lCsNQAU
hope it helps.Please mark it as best answer if the information is informative.
Thanks
Rahul Kumar
I have the same requirement, have you acheived this? please help me if you have.
Thanks,
Unfortunately, I haven't found any solution to do the singning from SF so I have done the signing from external system and pushed the document to SF to attach in the email.
Please note the process will impact the delivery time of email to end users so you should consider this option only if you are fine with it.
Thanks
Thanks for the reply, I am fine with the delay in the delivery time, Could you tell me how you did it using external System, I am in urgent need of this implementation, I exactly need what you mentioned above.
Please help me with the code.
Thanks