1

Something related to Digital signature

if we have a doc in sales-force and needs to be digitally signed, which involves digital certificates.. and how we can use crypto class of apex in this. also how to verify that Digital signature in other peer for authenticity and integrity of the message.

If its come to digital signature, We use private and public key certificate for encrypt and decrypt the message. then how i can generate a public and private certificate in salesforce certificate key management.

Needed very solution very badly for this, Any help can be appreciated.

  • i have a code for signing the document and the sign will store in the attachment of the object using visual force page and apex class @NITHESH K – SFDC Aug 31 '17 at 6:41
  • Can share me a code of that for understanding . My this question also related my one more question present in StackExchange salesforce.stackexchange.com/questions/190290/… – NITHESH K Aug 31 '17 at 6:45
  • but i have not use crypto, just using vf page and apex class, it will capture the sign and store in the attachment of the particular object – SFDC Aug 31 '17 at 6:46
  • 1
    i have created the custom button like signature , if you click that button, the box will open , after that i will sign in that box , down save button will be there,if you click save then it will store in the attachment of the object – SFDC Aug 31 '17 at 6:49
  • 1
    Can u share what you have done, So that i can get any idea about that – NITHESH K Aug 31 '17 at 7:15
2

Apex class for capturing the sign

public class signAccountExtension {
    Id accountId;

    public string fileData { get; set; }

    public signAccountExtension(ApexPages.StandardController controller) {
        accountId = controller.getId();
    }
    public void saveImage() {
        insert new Attachment(
            ContentType='image/jpeg',
            Body=EncodingUtil.base64Decode(fileData),
            Name='Signature',
            ParentId = accountId
        );
    }
}

Visual Force Page:

<apex:page standardController="Account" extensions="signAccountExtension">
    <style>
        #signature {
        border: 1px solid black;
        }
    </style>
    <apex:form id="form">
        <apex:actionFunction action="{!saveImage}" name="saveImageToServer" reRender="">
            <apex:param assignTo="{!fileData}" name="data" value="" />
        </apex:actionFunction>
        <canvas id="signature" width="400" height="100" />
        <button id="save">
            Save
        </button>
    </apex:form>
    <script>
    !function() {
        var canvas, lastX, lastY;
        function start(event) {
            lastX = event.offsetX;
            lastY = event.offsetY;
            document.body.addEventListener("mousemove", draw);
            document.body.addEventListener("mouseup", end);
        }
        function draw(event) {
            var context = canvas.getContext("2d");

            if(event.target === canvas) {
                context.fillStyle = "black";
                context.strokeStyle = "black";
                context.beginPath();
                context.moveTo(lastX, lastY);
                context.lineTo(event.offsetX, event.offsetY, 3);
                context.stroke();
                lastX = event.offsetX;
                lastY = event.offsetY;
            }
            event.preventDefault();
        }
        function end(event) {
            document.body.removeEventListener("mousemove", draw);
            document.body.removeEventListener("mouseup", end);
            canvas.removeEventListener("mouseenter", mouseenter);
            event.preventDefault();
        }
        function save(event) {
            event.preventDefault();
            saveImageToServer(canvas.toDataURL("image/jpeg").split(/;base64,/)[1]);
        }
        function init() {
            var context;
            canvas = document.getElementById("signature");
            canvas.addEventListener("mousedown", start);


            context = canvas.getContext("2d");
            context.fillStyle = "white";
            context.fillRect(0, 0, canvas.width, canvas.height);

            document.getElementById("save").addEventListener("click", save);
        }
        window.addEventListener('DOMContentLoaded', init);
    }()
    </script>
</apex:page>
  • Yes i read about this solution before .There storing in attachment , Signature draw in canvas window .. – NITHESH K Aug 31 '17 at 7:23
  • but i dont know about your using crtfile requirement,i have done like this manner only – SFDC Aug 31 '17 at 7:24
  • this i kind alternative for storing the signature. if you look developer.salesforce.com/docs/atlas.en-us.apexcode.meta/… , click on funcion "signWithCertificate(algorithmName, input, certDevName)" this method will generate a signature based on org certificate and input file . – NITHESH K Aug 31 '17 at 7:26
  • No problem, I appreciated for your help. – NITHESH K Aug 31 '17 at 7:28
  • 1
    Yes, i am looking alternative solution for my question. it was my project requirement so. – NITHESH K Aug 31 '17 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.