<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to read-out the informations in SSL certificates ?]]></title><description><![CDATA[<p dir="auto">Hello, i have prolblem by read out informations like CountryName. ... in a cert.<br />
here is some code, which i have done so far.</p>
<pre><code>        QNetworkProxyFactory::setUseSystemConfiguration(true);

        QMessageBox::information(window(),
        tr("Information"),
        tr("Please select a folder with ca certificates."));
        //
        QString dir = QFileDialog::getExistingDirectory(
            this, tr("Open Directory"),
            QDir::homePath(),
            QFileDialog::ShowDirsOnly |
            QFileDialog::DontResolveSymlinks);

        if (dir.trimmed().length() &lt; 2)
            dir = "/tmp";

        // ca certs ...
        QFileInfo fkey(QString("%1/ca.key.pem").arg(dir));
        QFileInfo fcrt(QString("%1/ca.crt.pem").arg(dir));

        if (!fkey.exists()) { QMessageBox::warning(window(),tr("Error"),tr("ca.key.pem not found.")); return; }
        if (!fcrt.exists()) { QMessageBox::warning(window(),tr("Error"),tr("ca.crt.pem not found.")); return; }

        QFile keyFile(QString("%1/ca.key.pem").arg(dir));
        QFile crtFile(QString("%1/ca.crt.pem").arg(dir));

        if (!keyFile.open(QIODevice::ReadOnly)) { QMessageBox::warning(window(),tr("ERROR"),tr("ca.key.pem not found.")); return; }
        if (!crtFile.open(QIODevice::ReadOnly)) { QMessageBox::warning(window(),tr("ERROR"),tr("ca.crt.pem not found.")); return; }

        const QByteArray keyBytes = keyFile.readAll();
        const QByteArray crtBytes = crtFile.readAll();

        if (keyBytes.trimmed().length() &lt; 2) { msgError(1); return; }
        if (crtBytes.trimmed().length() &lt; 2) { msgError(2); return; }

        QSslCertificate keyCert(keyBytes);
        QSslCertificate crtCert(crtBytes);

        QByteArray pass = "test";
        QSslKey privateKey(keyBytes,QSsl::Rsa,QSsl::Pem,QSsl::PrivateKey, pass);
        if (privateKey.isNull()) {
            QMessageBox::warning(window(),
            tr("Error"),
            tr("private key error."));
            return;
        }   else {
            QMessageBox::warning(window(),
            tr("info"),
            tr("private key ok"));
        }

        QSslConfiguration sslConfiguration;

        sslConfiguration.setPrivateKey(privateKey);
        sslConfiguration.setLocalCertificate(crtCert);
        sslConfiguration.setProtocol(QSsl::TlsV1_0);

        // fake test ...
        QNetworkAccessManager networkAccessManager;
        QNetworkRequest       networkRequest(QUrl("https://www.google.com/"));
        QNetworkReply *       networkReply
        = networkAccessManager.get(networkRequest);

        QEventLoop loop;
        QObject::connect(
            &amp;networkAccessManager,
            &amp;QNetworkAccessManager::finished,
            &amp;loop,
            &amp;QEventLoop::quit);
        loop.exec();

        if (networkReply-&gt;error() &gt; 0) {
            QMessageBox::information(window(),tr("info"),
            QString("code: %1\nerror: %2")
            .arg(networkReply-&gt;error())
            .arg(networkReply-&gt;errorString()));
            delete networkReply;
            return;
        }

        delete networkReply;

        keyFile.close();
        crtFile.close();

        QMessageBox::warning(window(),
        tr("Error"),
        QString("cert: %1").arg(keyCert.expiryDate().toString()));
        return;
</code></pre>
]]></description><link>https://forum.qt.io/topic/115127/how-to-read-out-the-informations-in-ssl-certificates</link><generator>RSS for Node</generator><lastBuildDate>Sat, 12 Sep 2026 19:40:16 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/115127.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 23 May 2020 19:26:26 GMT</pubDate><ttl>60</ttl></channel></rss>