当前位置: 首页>>代码示例>>C++>>正文


C++ PublicKey类代码示例

本文整理汇总了C++中PublicKey的典型用法代码示例。如果您正苦于以下问题:C++ PublicKey类的具体用法?C++ PublicKey怎么用?C++ PublicKey使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PublicKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: notarize

Bool SignerReal::notarize( PublicKey pubkey, Signature signature, Digest hash, Monitor& monitor )
{
	if (!check_interface(monitor)) return false;

	eprovider::TheKey thepubkey = creator.getCreatureCurrentTheKey(pubkey);
	Size hashsize;
	RECOVER_CALL(hashsize = iface->getMaxHashSize(thepubkey, error));
	
	Padder curpad = padder;
	if (pubkey.getPadder(Monitor()))
	{
		curpad = pubkey.getPadder(monitor);
	} else if (signature.getPadder(Monitor()))
	{
		curpad = signature.getPadder(monitor);
	} else {
		//TODO: find default padder
	}

	if (curpad.ok() && hashsize.bits()) hash = curpad.pad(hash, hashsize, monitor); if (!monitor) return Bool();
	Data hashblock = hash.asData();
	
	Image signimage = signature.encode(monitor);
	Snapshot signblock = signimage.snapshot();

	Bool result;
	
	RECOVER_CALL( (result = iface->notarizeHash(session,hashblock.get(), hashblock.size(), signblock.get(), signblock.size(), signblock.encid(), thepubkey, error)) );

	return result;
}
开发者ID:relonger,项目名称:ECryptoLib,代码行数:31,代码来源:SignerReal.cpp

示例2: verifyDigest

bool
verifyDigest (PublicKey const& publicKey,
    uint256 const& digest,
    Slice const& sig,
    bool mustBeFullyCanonical)
{
    if (publicKeyType(publicKey) != KeyType::secp256k1)
        LogicError("sign: secp256k1 required for digest signing");
    auto const canonicality = ecdsaCanonicality(sig);
    if (! canonicality)
        return false;
    if (mustBeFullyCanonical &&
        (*canonicality != ECDSACanonicality::fullyCanonical))
        return false;

    secp256k1_pubkey pubkey_imp;
    if(secp256k1_ec_pubkey_parse(
            secp256k1Context(),
            &pubkey_imp,
            reinterpret_cast<unsigned char const*>(
                publicKey.data()),
            publicKey.size()) != 1)
        return false;

    secp256k1_ecdsa_signature sig_imp;
    if(secp256k1_ecdsa_signature_parse_der(
            secp256k1Context(),
            &sig_imp,
            reinterpret_cast<unsigned char const*>(
                sig.data()),
            sig.size()) != 1)
        return false;
    if (*canonicality != ECDSACanonicality::fullyCanonical)
    {
        secp256k1_ecdsa_signature sig_norm;
        if(secp256k1_ecdsa_signature_normalize(
                secp256k1Context(),
                &sig_norm,
                &sig_imp) != 1)
            return false;
        return secp256k1_ecdsa_verify(
            secp256k1Context(),
            &sig_norm,
            reinterpret_cast<unsigned char const*>(
                digest.data()),
            &pubkey_imp) == 1;
    }
    return secp256k1_ecdsa_verify(
        secp256k1Context(),
        &sig_imp,
        reinterpret_cast<unsigned char const*>(
            digest.data()),
        &pubkey_imp) == 1;
}
开发者ID:mellery451,项目名称:rippled,代码行数:54,代码来源:PublicKey.cpp

示例3: Answer

/*
    Calculation of the Account ID

    The AccountID is a 160-bit identifier that uniquely
    distinguishes an account. The account may or may not
    exist in the ledger. Even for accounts that are not in
    the ledger, cryptographic operations may be performed
    which affect the ledger. For example, designating an
    account not in the ledger as a regular key for an
    account that is in the ledger.

    Why did we use half of SHA512 for most things but then
    SHA256 followed by RIPEMD160 for account IDs? Why didn't
    we do SHA512 half then RIPEMD160? Or even SHA512 then RIPEMD160?
    For that matter why RIPEMD160 at all why not just SHA512 and keep
    only 160 bits?

    Answer (David Schwartz):

        The short answer is that we kept Bitcoin's behavior.
        The longer answer was that:
            1) Using a single hash could leave ripple
               vulnerable to length extension attacks.
            2) Only RIPEMD160 is generally considered safe at 160 bits.

        Any of those schemes would have been acceptable. However,
        the one chosen avoids any need to defend the scheme chosen.
        (Against any criticism other than unnecessary complexity.)

        "The historical reason was that in the very early days,
        we wanted to give people as few ways to argue that we were
        less secure than Bitcoin. So where there was no good reason
        to change something, it was not changed."
*/
AccountID
calcAccountID (PublicKey const& pk)
{
    ripesha_hasher rsh;
    rsh(pk.data(), pk.size());
    auto const d = static_cast<
        ripesha_hasher::result_type>(rsh);
    AccountID id;
    static_assert(sizeof(d) == sizeof(id), "");
    std::memcpy(id.data(), d.data(), d.size());
    return id;
}
开发者ID:E-LLP,项目名称:rippled,代码行数:46,代码来源:AccountID.cpp

示例4: groupParameters

const KeyPair* EllipticCurveCryptographyFactory::generateKeyPair(const CryptoPP::OID& curveId) {
	CryptoPP::DL_GroupParameters_EC<CryptoPP::ECP> groupParameters(curveId);
	CryptoPP::ECDH<CryptoPP::ECP>::Domain ecdh(groupParameters);

	PublicKey* pub = new PublicKey(ecdh.PublicKeyLength());
	PrivateKey* priv = new PrivateKey(ecdh.PrivateKeyLength());

	CryptoPP::AutoSeededRandomPool rng;
	ecdh.GenerateKeyPair(rng, priv->data(), pub->data());

	KeyPair* keys = new KeyPair(pub, priv);
	return keys;
}
开发者ID:pascalgn,项目名称:encrypteddns,代码行数:13,代码来源:EllipticCurveCryptographyFactory.cpp

示例5: calcNodeID

NodeID
calcNodeID (PublicKey const& pk)
{
    ripesha_hasher h;
    h(pk.data(), pk.size());
    auto const digest = static_cast<
        ripesha_hasher::result_type>(h);
    static_assert(NodeID::bytes ==
        sizeof(ripesha_hasher::result_type), "");
    NodeID result;
    std::memcpy(result.data(),
        digest.data(), digest.size());
    return result;
}
开发者ID:mellery451,项目名称:rippled,代码行数:14,代码来源:PublicKey.cpp

示例6: verify

bool
verify (PublicKey const& publicKey,
    Slice const& m,
    Slice const& sig,
    bool mustBeFullyCanonical)
{
    if (auto const type = publicKeyType(publicKey))
    {
        if (*type == KeyType::secp256k1)
        {
            return verifyDigest (publicKey,
                sha512Half(m), sig, mustBeFullyCanonical);
        }
        else if (*type == KeyType::ed25519)
        {
            if (! ed25519Canonical(sig))
                return false;

            // We internally prefix Ed25519 keys with a 0xED
            // byte to distinguish them from secp256k1 keys
            // so when verifying the signature, we need to
            // first strip that prefix.
            return ed25519_sign_open(
                m.data(), m.size(), publicKey.data() + 1,
                    sig.data()) == 0;
        }
    }
    return false;
}
开发者ID:mellery451,项目名称:rippled,代码行数:29,代码来源:PublicKey.cpp

示例7: getKey

	static PublicKey getKey(Provider *p, const I &in, const QSecureArray &, ConvertResult *result)
	{
		PublicKey k;
		PKeyContext *c = static_cast<PKeyContext *>(getContext("pkey", p));
		if(!c)
		{
			if(result)
				*result = ErrorDecode;
			return k;
		}
		ConvertResult r = fromData(c, in);
		if(result)
			*result = r;
		if(r == ConvertGood)
			k.change(c);
		return k;
	}
开发者ID:sapo,项目名称:sapo-messenger-for-mac,代码行数:17,代码来源:qca_publickey.cpp

示例8: verify

bool Signer::verify(
        const std::vector<unsigned char> &data,
        const std::vector<unsigned char> &signature,
        const PublicKey &key) const
{
    kulloAssert(key.type() == AsymmetricKeyType::Signature);

    Botan::PK_Verifier ver(*key.p->pubkey, EMSA);
    return ver.verify_message(data, signature);
}
开发者ID:kullo,项目名称:client-libkullo,代码行数:10,代码来源:signer.cpp

示例9: STObject

STValidation::STValidation(
    uint256 const& ledgerHash,
    std::uint32_t ledgerSeq,
    uint256 const& consensusHash,
    NetClock::time_point signTime,
    PublicKey const& publicKey,
    SecretKey const& secretKey,
    NodeID const& nodeID,
    bool isFull,
    FeeSettings const& fees,
    std::vector<uint256> const& amendments)
    : STObject(getFormat(), sfValidation), mNodeID(nodeID), mSeen(signTime)
{
    // This is our own public key and it should always be valid.
    if (!publicKeyType(publicKey))
        LogicError("Invalid validation public key");
    assert(mNodeID.isNonZero());
    setFieldH256(sfLedgerHash, ledgerHash);
    setFieldH256(sfConsensusHash, consensusHash);
    setFieldU32(sfSigningTime, signTime.time_since_epoch().count());

    setFieldVL(sfSigningPubKey, publicKey.slice());
    if (isFull)
        setFlag(kFullFlag);

    setFieldU32(sfLedgerSequence, ledgerSeq);

    if (fees.loadFee)
        setFieldU32(sfLoadFee, *fees.loadFee);

    if (fees.baseFee)
        setFieldU64(sfBaseFee, *fees.baseFee);

    if (fees.reserveBase)
        setFieldU32(sfReserveBase, *fees.reserveBase);

    if (fees.reserveIncrement)
        setFieldU32(sfReserveIncrement, *fees.reserveIncrement);

    if (!amendments.empty())
        setFieldV256(sfAmendments, STVector256(sfAmendments, amendments));

    setFlag(vfFullyCanonicalSig);

    auto const signingHash = getSigningHash();
    setFieldVL(
        sfSignature, signDigest(getSignerPublic(), secretKey, signingHash));

    setTrusted();
}
开发者ID:mellery451,项目名称:rippled,代码行数:50,代码来源:STValidation.cpp

示例10: LogicError

Ed25519::Ed25519 (
    SecretKey const& secretKey,
    PublicKey const& publicKey,
    Slice message)
{
    if (publicKeyType (publicKey) != KeyType::ed25519)
        LogicError ("An Ed25519 public key is required.");

    // When PublicKey wraps an Ed25519 key it prefixes
    // the key itself with a 0xED byte. We carefully
    // skip that byte.
    std::memcpy (
        payload_.data(),
        publicKey.data() + 1,
        publicKey.size() - 1);

    // Now sign:
    ed25519_sign (
        message.data(),
        message.size(),
        secretKey.data(),
        payload_.data(),
        payload_.data() + pubkey_size_);
}
开发者ID:,项目名称:,代码行数:24,代码来源:

示例11: addIdentity

int64_t
PibDb::addKey(const Name& keyName, const PublicKey& key)
{
  if (keyName.empty())
    return 0;

  Name&& identity = keyName.getPrefix(-1);
  if (!hasIdentity(identity))
    addIdentity(identity);

  sqlite3_stmt* statement;
  sqlite3_prepare_v2(m_database,
                     "INSERT INTO keys (identity_id, key_name, key_type, key_bits) \
                      values ((SELECT id FROM identities WHERE identity=?), ?, ?, ?)",
                     -1, &statement, nullptr);
  sqlite3_bind_block(statement, 1, identity.wireEncode(), SQLITE_TRANSIENT);
  sqlite3_bind_block(statement, 2, keyName.wireEncode(), SQLITE_TRANSIENT);
  sqlite3_bind_int(statement, 3, key.getKeyType());
  sqlite3_bind_blob(statement, 4, key.get().buf(), key.get().size(), SQLITE_STATIC);
  sqlite3_step(statement);
  sqlite3_finalize(statement);

  return sqlite3_last_insert_rowid(m_database);
}
开发者ID:CSUL,项目名称:ndn-tools,代码行数:24,代码来源:pib-db.cpp

示例12: certificate

ptr_lib::shared_ptr<IdentityCertificate>
IdentityManager::createIdentityCertificate(const Name& certificatePrefix,
                                           const PublicKey& publicKey,
                                           const Name& signerCertificateName,
                                           const MillisecondsSince1970& notBefore,
                                           const MillisecondsSince1970& notAfter)
{
  ptr_lib::shared_ptr<IdentityCertificate> certificate(new IdentityCertificate());
  Name keyName = getKeyNameFromCertificatePrefix(certificatePrefix);

  Name certificateName = certificatePrefix;
  MillisecondsSince1970 ti = ::ndn_getNowMilliseconds();
  // Get the number of seconds.
  ostringstream oss;
  oss << floor(ti / 1000.0);

  certificateName.append("ID-CERT").append(oss.str());

  certificate->setName(certificateName);
  certificate->setNotBefore(notBefore);
  certificate->setNotAfter(notAfter);
  certificate->setPublicKeyInfo(publicKey);
  certificate->addSubjectDescription(CertificateSubjectDescription("2.5.4.41", keyName.toUri()));
  certificate->encode();

  ptr_lib::shared_ptr<Sha256WithRsaSignature> sha256Sig(new Sha256WithRsaSignature());

  KeyLocator keyLocator;
  keyLocator.setType(ndn_KeyLocatorType_KEYNAME);
  keyLocator.setKeyName(signerCertificateName);

  sha256Sig->setKeyLocator(keyLocator);
  sha256Sig->getPublisherPublicKeyDigest().setPublisherPublicKeyDigest(publicKey.getDigest());

  certificate->setSignature(*sha256Sig);

  SignedBlob unsignedData = certificate->wireEncode();

  ptr_lib::shared_ptr<IdentityCertificate> signerCertificate = getCertificate(signerCertificateName);
  Name signerkeyName = signerCertificate->getPublicKeyName();

  Blob sigBits = privateKeyStorage_->sign(unsignedData, signerkeyName);

  sha256Sig->setSignature(sigBits);

  return certificate;
}
开发者ID:,项目名称:,代码行数:47,代码来源:

示例13: STObject

STValidation::STValidation (
        uint256 const& ledgerHash,
        NetClock::time_point signTime,
        PublicKey const& publicKey,
        bool isFull)
    : STObject (getFormat (), sfValidation)
    , mSeen (signTime)
{
    // Does not sign
    setFieldH256 (sfLedgerHash, ledgerHash);
    setFieldU32 (sfSigningTime, signTime.time_since_epoch().count());

    setFieldVL (sfSigningPubKey, publicKey.slice());
    mNodeID = calcNodeID(publicKey);
    assert (mNodeID.isNonZero ());

    if (isFull)
        setFlag (kFullFlag);
}
开发者ID:dreamsxin,项目名称:rippled,代码行数:19,代码来源:STValidation.cpp

示例14: Key

Key
Identity::addKey(const PublicKey& publicKey, const name::Component& keyId)
{
  validityCheck();

  name::Component actualKeyId = keyId;
  if (actualKeyId == EMPTY_KEY_ID) {
    const Block& digest = publicKey.computeDigest();
    actualKeyId = name::Component(digest.wire(), digest.size());
  }

  if (!m_needRefreshKeys && m_keys.find(actualKeyId) == m_keys.end()) {
    // if we have already loaded all the keys, but the new key is not one of them
    // the KeyContainer should be refreshed
    m_needRefreshKeys = true;
  }

  return Key(m_name, actualKeyId, publicKey, m_impl);
}
开发者ID:AaronTien,项目名称:ndn-cxx,代码行数:19,代码来源:identity.cpp

示例15: fromHexString

		PublicKey PublicKey::fromHexString(QString const& hexString) {
			PublicKey pk;
			pk.publicKey = QByteArray::fromHex(hexString.toLatin1());
			pk.calculateFingerprintFromPublicKey();
			return pk;
		}
开发者ID:blizzard4591,项目名称:openMittsu,代码行数:6,代码来源:PublicKey.cpp


注:本文中的PublicKey类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。