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


C++ SecureVector::data方法代码示例

本文整理汇总了C++中botan::SecureVector::data方法的典型用法代码示例。如果您正苦于以下问题:C++ SecureVector::data方法的具体用法?C++ SecureVector::data怎么用?C++ SecureVector::data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在botan::SecureVector的用法示例。


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

示例1: ExtractFromWad

    EpadResult ExtractFromWad(RandomInStream &in, OutStream &out, std::string &key_file)
    {
        WadMetadata metadata;
        auto result = ExtractWadMetadata(in, in.GetCount(), metadata);
        in.Seek(metadata.payload_offset);

        if(result != EpadResult::Success)
            return result;

        Botan::SecureVector<byte> buffer;
        buffer.resize(metadata.payload_size != 0 ? metadata.payload_size : in.GetCount());
        in.Read(buffer.data(), buffer.size());
        out.Write(buffer.data(), buffer.size());

        key_file.clear();

        if(metadata.key_file_offset != kInvalid)
        {
            key_file.resize(metadata.key_file_size);
            in.Seek(metadata.key_file_offset);
            in.Read(reinterpret_cast<byte *>(&*key_file.begin()), metadata.key_file_size);
        }

        return EpadResult::Success;
    }
开发者ID:evpo,项目名称:EncryptPad,代码行数:25,代码来源:wad_reader_writer.cpp

示例2: signFinal

bool BotanRSA::signFinal(ByteString& signature)
{
	if (!AsymmetricAlgorithm::signFinal(signature))
	{
		return false;
	}

	// Perform the signature operation
#if BOTAN_VERSION_MINOR == 11
	std::vector<Botan::byte> signResult;
#else
	Botan::SecureVector<Botan::byte> signResult;
#endif
	try
	{
		BotanRNG* rng = (BotanRNG*)BotanCryptoFactory::i()->getRNG();
		signResult = signer->signature(*rng->getRNG());
	}
	catch (...)
	{
		ERROR_MSG("Could not sign the data");

		delete signer;
		signer = NULL;

		return false;
	}

	// Return the result
	signature.resize(signResult.size());
#if BOTAN_VERSION_MINOR == 11
	memcpy(&signature[0], signResult.data(), signResult.size());
#else
	memcpy(&signature[0], signResult.begin(), signResult.size());
#endif

	delete signer;
	signer = NULL;

	return true;
}
开发者ID:bluelikeme,项目名称:SoftHSMv2,代码行数:41,代码来源:BotanRSA.cpp

示例3: encrypt

// Encryption functions
bool BotanRSA::encrypt(PublicKey* publicKey, const ByteString& data,
		       ByteString& encryptedData, const AsymMech::Type padding)
{
	// Check if the public key is the right type
	if (!publicKey->isOfType(BotanRSAPublicKey::type))
	{
		ERROR_MSG("Invalid key type supplied");

		return false;
	}

	std::string eme;

	switch (padding)
	{
		case AsymMech::RSA_PKCS:
			eme = "PKCS1v15";
			break;
		case AsymMech::RSA_PKCS_OAEP:
			eme = "EME1(SHA-160)";
			break;
		case AsymMech::RSA:
			eme = "Raw";
			break;
		default:
			ERROR_MSG("Invalid padding mechanism supplied (%i)", padding);

			return false;
	}

	BotanRSAPublicKey* pk = (BotanRSAPublicKey*) publicKey;
	Botan::RSA_PublicKey* botanKey = pk->getBotanKey();

	if (!botanKey)
	{
		ERROR_MSG("Could not get the Botan public key");

		return false;
	}

	Botan::PK_Encryptor_EME* encryptor = NULL;
	try
	{
		encryptor = new Botan::PK_Encryptor_EME(*botanKey, eme);
	}
	catch (...)
	{
		ERROR_MSG("Could not create the encryptor token");

		return false;
	}

	// Perform the encryption operation
#if BOTAN_VERSION_MINOR == 11
	std::vector<Botan::byte> encResult;
#else
	Botan::SecureVector<Botan::byte> encResult;
#endif
	try
	{
		BotanRNG* rng = (BotanRNG*)BotanCryptoFactory::i()->getRNG();
		encResult = encryptor->encrypt(data.const_byte_str(), data.size(), *rng->getRNG());
	}
	catch (...)
	{
		ERROR_MSG("Could not encrypt the data");

		delete encryptor;

		return false;
	}

	// Return the result
	encryptedData.resize(encResult.size());
#if BOTAN_VERSION_MINOR == 11
	memcpy(&encryptedData[0], encResult.data(), encResult.size());
#else
	memcpy(&encryptedData[0], encResult.begin(), encResult.size());
#endif

	delete encryptor;

	return true;
}
开发者ID:bluelikeme,项目名称:SoftHSMv2,代码行数:85,代码来源:BotanRSA.cpp

示例4: sign

// Signing functions
bool BotanRSA::sign(PrivateKey* privateKey, const ByteString& dataToSign,
		    ByteString& signature, const AsymMech::Type mechanism,
		    const void* param /* = NULL */, const size_t paramLen /* = 0 */)
{
	std::string emsa = "";

	switch (mechanism)
	{
		case AsymMech::RSA:
			emsa = "Raw";
			break;
		case AsymMech::RSA_PKCS:
			emsa = "EMSA3(Raw)";
			break;
		default:
			// Call default implementation
			return AsymmetricAlgorithm::sign(privateKey, dataToSign, signature, mechanism, param, paramLen);
	}

	// Check if the private key is the right type
	if (!privateKey->isOfType(BotanRSAPrivateKey::type))
	{
		ERROR_MSG("Invalid key type supplied");

		return false;
	}

	BotanRSAPrivateKey* pk = (BotanRSAPrivateKey*) privateKey;
	Botan::RSA_PrivateKey* botanKey = pk->getBotanKey();

	if (!botanKey)
	{
		ERROR_MSG("Could not get the Botan private key");

		return false;
	}

	try
	{
		signer = new Botan::PK_Signer(*botanKey, emsa);
		// Should we add DISABLE_FAULT_PROTECTION? Makes this operation faster.
	}
	catch (...)
	{
		ERROR_MSG("Could not create the signer token");

		return false;
	}

	// Perform the signature operation
#if BOTAN_VERSION_MINOR == 11
	std::vector<Botan::byte> signResult;
#else
	Botan::SecureVector<Botan::byte> signResult;
#endif
	try
	{
		BotanRNG* rng = (BotanRNG*)BotanCryptoFactory::i()->getRNG();
		signResult = signer->sign_message(dataToSign.const_byte_str(), dataToSign.size(), *rng->getRNG());
	}
	catch (std::exception& e)
	{
		ERROR_MSG("Could not sign the data: %s", e.what());

		delete signer;
		signer = NULL;

		return false;
	}

	// Return the result
	signature.resize(signResult.size());
#if BOTAN_VERSION_MINOR == 11
	memcpy(&signature[0], signResult.data(), signResult.size());
#else
	memcpy(&signature[0], signResult.begin(), signResult.size());
#endif

	delete signer;
	signer = NULL;

	return true;
}
开发者ID:bluelikeme,项目名称:SoftHSMv2,代码行数:84,代码来源:BotanRSA.cpp

示例5: sign

// Signing functions
bool BotanRSA::sign(PrivateKey* privateKey, const ByteString& dataToSign, ByteString& signature, const
                    std::string mechanism)
{
    std::string lowerMechanism;
    lowerMechanism.resize(mechanism.size());
    std::transform(mechanism.begin(), mechanism.end(), lowerMechanism.begin(), tolower);
    std::string emsa = "";

    if (!lowerMechanism.compare("rsa-pkcs"))
    {
        emsa = "EMSA3(Raw)";
    }
    else if (!lowerMechanism.compare("rsa-raw"))
    {
        emsa = "Raw";
    }
    else
    {
        // Call default implementation
        return AsymmetricAlgorithm::sign(privateKey, dataToSign, signature, mechanism);
    }

    // Check if the private key is the right type
    if (!privateKey->isOfType(BotanRSAPrivateKey::type))
    {
        ERROR_MSG("Invalid key type supplied");

        return false;
    }

    BotanRSAPrivateKey* pk = (BotanRSAPrivateKey*) privateKey;
    Botan::RSA_PrivateKey* botanKey = pk->getBotanKey();

    if (!botanKey)
    {
        ERROR_MSG("Could not get the Botan private key");

        return false;
    }

    try
    {
        signer = new Botan::PK_Signer(*botanKey, emsa);
        // Should we add DISABLE_FAULT_PROTECTION? Makes this operation faster.
    }
    catch (...)
    {
        ERROR_MSG("Could not create the signer token");

        return false;
    }

    // Perform the signature operation
#if BOTAN_VERSION_MINOR == 11
    std::vector<Botan::byte> signResult;
#else
    Botan::SecureVector<Botan::byte> signResult;
#endif
    try
    {
        BotanRNG* rng = (BotanRNG*)BotanCryptoFactory::i()->getRNG();
        signResult = signer->sign_message(dataToSign.const_byte_str(), dataToSign.size(), *rng->getRNG());
    }
    catch (...)
    {
        ERROR_MSG("Could not sign the data");

        delete signer;
        signer = NULL;

        return false;
    }

    // Return the result
    signature.resize(signResult.size());
#if BOTAN_VERSION_MINOR == 11
    memcpy(&signature[0], signResult.data(), signResult.size());
#else
    memcpy(&signature[0], signResult.begin(), signResult.size());
#endif

    delete signer;
    signer = NULL;

    return true;
}
开发者ID:jelu,项目名称:SoftHSMv2,代码行数:87,代码来源:BotanRSA.cpp


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