本文整理汇总了C++中CKey::Verify方法的典型用法代码示例。如果您正苦于以下问题:C++ CKey::Verify方法的具体用法?C++ CKey::Verify怎么用?C++ CKey::Verify使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CKey
的用法示例。
在下文中一共展示了CKey::Verify方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsPrimeNodeKey
/* Check the script signature to confirm it came from a valid prime node key
* nTime is the time of the transaction/stake.
* entry is the resulting database entry if the script signature is valid. */
bool CPrimeNodeDB::IsPrimeNodeKey(CScript scriptPubKeyType, unsigned int nTime, CPrimeNodeDBEntry &entry) {
vector<CPrimeNodeDBEntry> primeNodeDBEntries;
Dbc* pcursor = GetCursor();
if (!pcursor)
throw runtime_error("IsPrimeNodeKey() : cannot create DB cursor");
unsigned int fFlags = DB_SET_RANGE;
for (;;)
{
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
if (fFlags == DB_SET_RANGE)
ssKey << make_pair(string("primenode"), string(""));
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
fFlags = DB_NEXT;
if (ret == DB_NOTFOUND)
break;
else if (ret != 0)
{
pcursor->close();
throw runtime_error("IsPrimeNodeKey() : error scanning DB");
}
// Unserialize
string strType;
ssKey >> strType;
if (strType != "primenode")
break;
CPrimeNodeDBEntry dbentry;
ssKey >> dbentry.key;
ssValue >> dbentry;
primeNodeDBEntries.push_back(dbentry);
}
pcursor->close();
BOOST_FOREACH(CPrimeNodeDBEntry dbentry, primeNodeDBEntries) {
vector<unsigned char> vchPubKey = ParseHex(dbentry.key);
CKey key;
key.SetPubKey(vchPubKey);
CScript scriptTime;
scriptTime << nTime;
uint256 hashScriptTime = Hash(scriptTime.begin(), scriptTime.end());
vector<unsigned char> vchSig;
vchSig.insert(vchSig.end(), scriptPubKeyType.begin() + 2, scriptPubKeyType.end());
if(key.Verify(hashScriptTime, vchSig)) {
entry = dbentry;
return true;
}
}
示例2: CheckSignature
bool CAlert::CheckSignature() const
{
CKey key;
if (!key.SetPubKey(ParseHex(fTestNet ? pszTestKey : pszMainKey)))
return error("CAlert::CheckSignature() : SetPubKey failed");
if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig))
return error("CAlert::CheckSignature() : verify signature failed");
// Now unserialize the data
CDataStream sMsg(vchMsg, SER_NETWORK, PROTOCOL_VERSION);
sMsg >> *(CUnsignedAlert*)this;
return true;
}
示例3: CheckSignature
// ppcoin: verify signature of sync-checkpoint message
bool CSyncCheckpoint::CheckSignature()
{
CKey key;
std::string strMasterPubKey = fTestNet? CSyncCheckpoint::strTestPubKey : CSyncCheckpoint::strMainPubKey;
if (!key.SetPubKey(ParseHex(strMasterPubKey)))
return error("CSyncCheckpoint::CheckSignature() : SetPubKey failed");
if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig))
return error("CSyncCheckpoint::CheckSignature() : verify signature failed");
// Now unserialize the data
CDataStream sMsg(vchMsg, SER_NETWORK, PROTOCOL_VERSION);
sMsg >> *(CUnsignedSyncCheckpoint*)this;
return true;
}
示例4: verifyNodePublic
bool RippleAddress::verifyNodePublic (uint256 const& hash, Blob const& vchSig) const
{
CKey pubkey = CKey ();
bool bVerified;
if (!pubkey.SetPubKey (getNodePublic ()))
{
// Failed to set public key.
bVerified = false;
}
else
{
bVerified = pubkey.Verify (hash, vchSig);
}
return bVerified;
}
示例5: verifyNodePublic
bool RippleAddress::verifyNodePublic(const uint256& hash, const std::vector<unsigned char>& vchSig) const
{
CKey pubkey = CKey();
bool bVerified;
if (!pubkey.SetPubKey(getNodePublic()))
{
// Failed to set public key.
bVerified = false;
}
else
{
bVerified = pubkey.Verify(hash, vchSig);
}
return bVerified;
}
示例6: accountPrivateVerify
bool RippleAddress::accountPrivateVerify(const uint256& uHash, const std::vector<unsigned char>& vucSig) const
{
CKey ckPrivate;
bool bVerified;
if (!ckPrivate.SetPrivateKeyU(getAccountPrivate()))
{
// Bad private key.
cLog(lsWARNING) << "accountPrivateVerify: Bad private key.";
bVerified = false;
}
else
{
bVerified = ckPrivate.Verify(uHash, vucSig);
}
return bVerified;
}
示例7: CheckSig
bool CheckSig(vector<unsigned char> vchSig, vector<unsigned char> vchPubKey, CScript scriptCode,
const CTransaction& txTo, unsigned int nIn, int nHashType)
{
CKey key;
if (!key.SetPubKey(vchPubKey))
return false;
// Hash type is one byte tacked on to the end of the signature
if (vchSig.empty())
return false;
if (nHashType == 0)
nHashType = vchSig.back();
else if (nHashType != vchSig.back())
return false;
vchSig.pop_back();
return key.Verify(SignatureHash(scriptCode, txTo, nIn, nHashType), vchSig);
}
示例8: accountPrivateVerify
bool RippleAddress::accountPrivateVerify (uint256 const& uHash, Blob const& vucSig) const
{
CKey ckPrivate;
bool bVerified;
if (!ckPrivate.SetPrivateKeyU (getAccountPrivate ()))
{
// Bad private key.
WriteLog (lsWARNING, RippleAddress) << "accountPrivateVerify: Bad private key.";
bVerified = false;
}
else
{
bVerified = ckPrivate.Verify (uHash, vucSig);
}
return bVerified;
}
示例9: accountPublicVerify
bool RippleAddress::accountPublicVerify (uint256 const& uHash, Blob const& vucSig, ECDSA fullyCanonical) const
{
CKey ckPublic;
bool bVerified = isCanonicalECDSASig (vucSig, fullyCanonical);
if (bVerified && !ckPublic.SetPubKey (getAccountPublic ()))
{
// Bad private key.
WriteLog (lsWARNING, RippleAddress) << "accountPublicVerify: Bad private key.";
bVerified = false;
}
else
{
bVerified = ckPublic.Verify (uHash, vucSig);
}
return bVerified;
}
示例10: verifyNodePublic
bool RippleAddress::verifyNodePublic (uint256 const& hash, Blob const& vchSig, ECDSA fullyCanonical) const
{
CKey pubkey = CKey ();
bool bVerified;
bVerified = isCanonicalECDSASig (vchSig, fullyCanonical);
if (bVerified && !pubkey.SetPubKey (getNodePublic ()))
{
// Failed to set public key.
bVerified = false;
}
else
{
bVerified = pubkey.Verify (hash, vchSig);
}
return bVerified;
}
示例11: on_verifyMessageButton_VM_clicked
void SignVerifyMessageDialog::on_verifyMessageButton_VM_clicked()
{
CBitcoinAddress addr(ui->addressIn_VM->text().toStdString());
if (!addr.IsValid())
{
ui->addressIn_VM->setValid(false);
ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_VM->setText(tr("The entered address is invalid.") + QString(" ") + tr("Please check the address and try again."));
return;
}
CKeyID keyID;
if (!addr.GetKeyID(keyID))
{
ui->addressIn_VM->setValid(false);
ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_VM->setText(tr("The entered address does not refer to a key.") + QString(" ") + tr("Please check the address and try again."));
return;
}
bool fInvalid = false;
std::vector<unsigned char> vchSig = DecodeBase64(ui->signatureIn_VM->text().toStdString().c_str(), &fInvalid);
if (fInvalid)
{
ui->signatureIn_VM->setValid(false);
ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_VM->setText(tr("The signature could not be decoded.") + QString(" ") + tr("Please check the signature and try again."));
return;
}
CDataStream ss(SER_GETHASH, 0);
ss << strMessageMagic;
ss << ui->messageIn_VM->document()->toPlainText().toStdString();
// get the public key from UI
fInvalid = false;
std::vector<unsigned char> vchPubKey = DecodeBase64(ui->pubkeyIn_VM->text().toStdString().c_str(), &fInvalid);
if (fInvalid)
{
ui->pubkeyIn_VM->setValid(false);
ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_VM->setText(tr("The public key could not be decoded.") + QString(" ") + tr("Please check it and try again."));
return;
}
CPubKey pubkey(vchPubKey);
if (!pubkey.IsValid())
{
ui->pubkeyIn_VM->setValid(false);
ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_VM->setText(tr("The public key is not valid.") + QString(" ") + tr("Please check it and try again."));
return;
}
CKey key;
if (!key.SetPubKey(pubkey))
{
ui->pubkeyIn_VM->setValid(false);
ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_VM->setText(tr("The public key cannot be added.") + QString(" ") + tr("Please check it and try again."));
return;
}
if (!key.Verify(HashKeccak(ss.begin(), ss.end()), vchSig))
{
ui->signatureIn_VM->setValid(false);
ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_VM->setText(tr("The signature did not match the message digest.") + QString(" ") + tr("Please check the signature and try again."));
return;
}
// TODO
// add the public key
//key.SetPubKey();
if (!(CBitcoinAddress(key.GetPubKey().GetID()) == addr))
{
ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_VM->setText(QString("<nobr>") + tr("Message verification failed.") + QString("</nobr>"));
return;
}
ui->statusLabel_VM->setStyleSheet("QLabel { color: green; }");
ui->statusLabel_VM->setText(QString("<nobr>") + tr("Message verified.") + QString("</nobr>"));
}