Exemple #1
0
        private TElX509Certificate LoadCertificate(string credentialsID, string access_token)
        {
            JsonSerializer        serializer     = new JsonSerializer();
            ErrorLogger           errorLogger    = new ErrorLogger();
            CredentialsInfoClient credInfoClient = new CredentialsInfoClient(serializer, errorLogger, baseURL);

            InputCredentialsInfo credentialsInfo = new InputCredentialsInfo()
            {
                credentialID = credentialsID
            };
            string temp = credInfoClient.GetCredentialsInfo(access_token, credentialsInfo).ToString();

            // string temp = serializer.Serialize(outputCredentials);
            if (!temp.Contains("error") && temp != "")
            {
                OutputCredentialsInfo output = serializer.Deserialize <OutputCredentialsInfo>(temp);

                string certificate = output.cert.certificates.FirstOrDefault();

                TElX509Certificate cert    = new TElX509Certificate();
                byte[]             certBuf = Encoding.UTF8.GetBytes(certificate);
                int r = cert.LoadFromBufferAuto(certBuf, 0, certBuf.Length, "");

                if (r != 0)
                {
                    throw new Exception("Certificate read error: " + r.ToString());
                }

                return(cert);
            }
            else
            {
                return(null);
            }
        }
        private TElMemoryCertStorage LoadCertificate(string credentialsID, string access_token)
        {
            //credentialsInfo
            JsonSerializer        serializer     = new JsonSerializer();
            ErrorLogger           errorLogger    = new ErrorLogger();
            CredentialsInfoClient credInfoClient = new CredentialsInfoClient(serializer, errorLogger, "https://msign-test.transsped.ro/csc/v0/");

            InputCredentialsInfo credentialsInfo = new InputCredentialsInfo()
            {
                credentialID = credentialsID
            };
            object outputCredentials = credInfoClient.GetCredentialsInfo(access_token, credentialsInfo);

            string temp = serializer.Serialize(outputCredentials);

            if (!temp.Contains("error"))
            {
                OutputCredentialsInfo output = serializer.Deserialize <OutputCredentialsInfo>(temp);

                string certificate = output.cert.certificates.FirstOrDefault();

                TElX509Certificate cert    = new TElX509Certificate();
                byte[]             certBuf = Encoding.UTF8.GetBytes(certificate);
                int r = cert.LoadFromBufferAuto(certBuf, 0, certBuf.Length, "");

                if (r != 0)
                {
                    throw new Exception("Certificate read error: " + r.ToString());
                }

                TElMemoryCertStorage storage = new TElMemoryCertStorage();
                storage.Add(cert, true);

                return(storage);
            }
            else
            {
                return(null);
            }
        }