Recently i came across a use case in my product where I have to accept a .CER file from User and pass the certificate to the backend services.
Due to some reason we were unable to handle the certificate file in backend so from UI side we have to extract the key from .CER file and pass it to the backend.
I started with a Google Search but didn’t got any solution for certificate transcription using Javascript. So I just gave a try by writing Javascript logic to extract string from text file (.txt) , and surprisingly i was able to extract the key from certificate using the same logic with some additional string formatter code.
To start with add FileUploader in your view
Add the following code in the controller
handleUploadComplete: function(oEvent) { var file = oEvent.getParameter(“files”) && oEvent.getParameter(“files”)[0]; if (file && window.FileReader) { var reader = new FileReader(); reader.onload = function(evn) { var certificate = evn.target.result; //string in CER //Now lets format the complete string, so that the key is in single line certificate = certificate.split(“n”); formated_certificate = certificate.slice(1, certificate.length – 2).join(“”); }; reader.readAsText(file); } }
Done!! http://bit.ly/2EdtMuX #SAP #SAPCloud #AI
Share this:
- Click to share on Facebook (Opens in new window)
- Click to share on Twitter (Opens in new window)
- Click to email a link to a friend (Opens in new window)
- Click to share on LinkedIn (Opens in new window)
- Click to share on Tumblr (Opens in new window)
- Click to share on Pinterest (Opens in new window)
- Click to share on Reddit (Opens in new window)