public static SSLConvertorResponse SSLConvertor(SSLConvertorRequest req)
        {
            SSLConvertorResponse Response = new SSLConvertorResponse();

            var    json        = JsonConvert.SerializeObject(req);
            string strResponse = ApiHelper.GetResponseFromAPI(json, "ssltools/sslconverter/");

            Response = JsonConvert.DeserializeObject <SSLConvertorResponse>(strResponse);

            return(Response);
        }
        public ActionResult sslconvertor(FormCollection collection)
        {
            SSLConvertorRequest req = new SSLConvertorRequest();

            req.AuthRequest     = GetAuthrequest();
            req.Certificate     = ReadPostedFile(Request.Files["inCertValid"]);
            req.ConvertFrom     = Request.Form["group_name"].ToString();
            req.ConvertTo       = Request.Form["chn_group_name"];
            req.IntermediatesCA = ReadPostedFile(Request.Files["chain1file"]) + "\n" + ReadPostedFile(Request.Files["chain2file"]);
            req.KeyPassword     = Request.Form["pfxkeypass"];
            req.PrivateKey      = ReadPostedFile(Request.Files["inprvKeyValid"]);
            req.RootCA          = Request.Form["RootCA"];
            SSLConvertorResponse objRestResponse = FreeSSLToolsService.SSLConvertor(req);

            try
            {
                if (!objRestResponse.AuthResponse.isError)
                {
                    string filename = "Certificate." + req.ConvertTo.ToLower();

                    byte[] bytContents = Convert.FromBase64String("");
                    if ((req.ConvertFrom.ToLower().Equals("pem") && req.ConvertTo.ToLower().Equals("der")) || (req.ConvertFrom.ToLower().Equals("pem") && req.ConvertTo.ToLower().Equals("pfx")) || (req.ConvertFrom.ToLower().Equals("p7b") && req.ConvertTo.ToLower().Equals("pfx")))
                    {
                        //fromb64

                        bytContents = Convert.FromBase64String(objRestResponse.Certificate);
                    }
                    else if ((req.ConvertFrom.ToLower().Equals("pem") && req.ConvertTo.ToLower().Equals("p7b")) || (req.ConvertFrom.ToLower().Equals("der") && req.ConvertTo.ToLower().Equals("pem")))
                    {
                        bytContents = Convert.FromBase64String(objRestResponse.Certificate);
                        //noneed from64
                    }
                    else if ((req.ConvertFrom.ToLower().Equals("pfx") && req.ConvertTo.ToLower().Equals("pem")) || (req.ConvertFrom.ToLower().Equals("p7b") && req.ConvertTo.ToLower().Equals("pem")))
                    {
                        //objRestResponse.ChainCertificates .cer
                        //objRestResponse.Certificate .cer
                        //objRestResponse.PrivateKey .key


                        System.IO.MemoryStream ms = new System.IO.MemoryStream();
                        using (ZipFile zip = new ZipFile())
                        {
                            if (!string.IsNullOrEmpty(objRestResponse.Certificate))
                            {
                                zip.AddEntry("Certificate.cer", objRestResponse.Certificate);
                            }
                            if (objRestResponse != null && objRestResponse.ChainCertificates.Count > 0)
                            {
                                int Count = 1;
                                foreach (string CA in objRestResponse.ChainCertificates)
                                {
                                    zip.AddEntry("CACerficate-" + Count.ToString() + ".cer", CA.ToString());
                                    Count++;
                                }
                            }
                            if (!(req.ConvertFrom.ToLower().Equals("p7b") && req.ConvertTo.ToLower().Equals("pem")))
                            {
                                if (!string.IsNullOrEmpty(objRestResponse.PrivateKey))
                                {
                                    zip.AddEntry("PrivateKey.key", objRestResponse.PrivateKey);
                                }
                            }
                            zip.Save(ms);

                            bytContents = ms.ToArray();
                        }

                        return(File(bytContents, "application/zip", "Certificate.zip"));
                    }

                    return(File(bytContents, "application/" + req.ConvertTo.ToLower(), filename));
                }
            }
            catch (Exception ex)
            {
                return(View(objRestResponse));
            }

            return(View());
        }