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 or Crypto.signWithCertificate 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 contents = pageRef.getContentAsPDF();
Blob contentNormal = pageRef.getContentAsPDF();
String algorithmName = 'RSA-SHA1';
String key = 'PKCS12 Key';
Blob privateKey = EncodingUtil.base64Decode(key);
Blob signature = Crypto.sign(algorithmName, contents, privateKey);
//Blob certificate = Crypto.signWithCertificate('RSA-SHA1', contents, 'Roojai_Web_Portal');
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setSubject('Test Subject');
mail.setHtmlBody('certificate');
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.setFileName('Test.pdf');
//attach.setBody(signature);
//attachments.add(attach);
attach = new Messaging.Emailfileattachment();
attach.setFileName('TestNormal.pdf');
attach.setBody(contentNormal);
attachments.add(attach);
mail.setFileAttachments(attachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Apex Page:
<apex:page >
This is a test page
</apex:page>
1 件の回答
Hi Anoop,
I would suggest you to redirect your question towards the Developer Community which you can find at http://developer.salesforce.com
Experienced developers will be able to help you out there with this!
Kind Regards,
Sourav