本文整理汇总了C++中CryptoKey::encodedPublicKey方法的典型用法代码示例。如果您正苦于以下问题:C++ CryptoKey::encodedPublicKey方法的具体用法?C++ CryptoKey::encodedPublicKey怎么用?C++ CryptoKey::encodedPublicKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CryptoKey
的用法示例。
在下文中一共展示了CryptoKey::encodedPublicKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildRequestData
bool ContactRequestClient::buildRequestData(QByteArray cookie)
{
/* [2*length][16*hostname][16*serverCookie][16*connSecret][data:pubkey][str:nick][str:message][data:signature] */
QByteArray requestData;
CommandDataParser request(&requestData);
/* Hostname */
QString hostname = user->hostname();
hostname.truncate(hostname.lastIndexOf(QLatin1Char('.')));
if (hostname.size() != 16)
{
qWarning() << "Cannot send contact request: unable to determine the remote service hostname";
return false;
}
/* Connection secret */
QByteArray connSecret = user->settings()->read<Base64Encode>("localSecret");
if (connSecret.size() != 16)
{
qWarning() << "Cannot send contact request: invalid local secret";
return false;
}
/* Public service key */
Tor::HiddenService *service = user->identity->hiddenService();
CryptoKey serviceKey;
if (!service || !(serviceKey = service->cryptoKey()).isLoaded())
{
qWarning() << "Cannot send contact request: failed to load service key";
return false;
}
QByteArray publicKeyData = serviceKey.encodedPublicKey();
if (publicKeyData.isNull())
{
qWarning() << "Cannot send contact request: failed to encode service key";
return false;
}
/* Build request */
request << (quint16)0; /* placeholder for length */
request.writeFixedData(hostname.toLatin1());
request.writeFixedData(cookie);
request.writeFixedData(connSecret);
request.writeVariableData(publicKeyData);
request << myNickname() << message();
if (request.hasError())
{
qWarning() << "Cannot send contact request: command building failed";
return false;
}
/* Sign request, excluding the length field */
QByteArray signature = serviceKey.signData(requestData.mid(2));
if (signature.isNull())
{
qWarning() << "Cannot send contact request: failed to sign request";
return false;
}
request.writeVariableData(signature);
if (request.hasError())
{
qWarning() << "Cannot send contact request: command building failed";
return false;
}
/* Set length */
qToBigEndian((quint16)requestData.size(), reinterpret_cast<uchar*>(requestData.data()));
/* Send */
qint64 re = socket->write(requestData);
Q_ASSERT(re == requestData.size());
Q_UNUSED(re);
qDebug() << "Contact request for" << user->uniqueID << "sent request data";
return true;
}