The public key of a given certificate as displayed by Windows when looking at the certificate details in Chrome differs from what Qt returns in a slot connected to the encrypted signal.
auto onEncrypt = [](QNetworkReply* rpl) {
auto cert = rpl->sslConfiguration().peerCertificate();
auto publicKey = cert.publicKey();
QString winHexKey = "3082010a0282010100d8..."; // as displayed in cert info of Chrome on Windows for the Public Key
auto windowsKey = QByteArray::fromHex(winHexKey.toUtf8());
if (windowsKey == publicKey.toPem())
std::cout << "PEM key matched\n";
else if (windowsKey == publicKey.toDer())
std::cout << "DER key matched\n";
else if (winHexKey == publicKey.toPem().toHex())
std::cout << "Hex PEM key matched\n";
else if (winHexKey == publicKey.toDer().toHex())
std::cout << "Hex DER key matched\n";
else
std::cout << "No match!\n";
std::cout << publicKey.toPem().toHex().toStdString() << '\n'; // 902 characters worth starting with 2d2d2d2d2d
};
QNetworkAccessManager mgr;
QObject::connect(&mgr, &QNetworkAccessManager::encrypted, onEncrypt);
QNetworkRequest r(QUrl::fromUserInput("https://www.qt.io"));
mgr.get(r);
Always results in No Match. Interestingly the Hex output of the public key is much much larger than whatever Windows displays.
How can one get the public key of the certificate presented by the server, and verify it against what is present in the certificate?