Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Extract key from certificate file in SAP UI5

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 =; //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("");




This post first appeared on Web Service Testing A Blackjack GUI And API, please read the originial post: here

Share the post

Extract key from certificate file in SAP UI5


Subscribe to Web Service Testing A Blackjack Gui And Api

Get updates delivered right to your inbox!

Thank you for your subscription