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


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

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


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

示例1: ToSeed

// passphrase must be at most 256 characters or code may crash
void CMnemonic::ToSeed(SecureString mnemonic, SecureString passphrase, SecureVector& seedRet)
{
    SecureString ssSalt = SecureString("mnemonic") + passphrase;
    SecureVector vchSalt(ssSalt.begin(), ssSalt.end());
    seedRet.resize(64);
    // int PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
    //                    const unsigned char *salt, int saltlen, int iter,
    //                    const EVP_MD *digest,
    //                    int keylen, unsigned char *out);
    PKCS5_PBKDF2_HMAC(mnemonic.c_str(), mnemonic.size(), &vchSalt[0], vchSalt.size(), 2048, EVP_sha512(), 64, &seedRet[0]);
}
开发者ID:prapun77,项目名称:monoeci,代码行数:12,代码来源:bip39.cpp

示例2: read_handshake

/*
* Split up and process handshake messages
*/
void TLS_Server::read_handshake(byte rec_type,
                                const MemoryRegion<byte>& rec_buf)
   {
   if(rec_type == HANDSHAKE)
      {
      if(!state)
         state = new Handshake_State;
      state->queue.write(&rec_buf[0], rec_buf.size());
      }

   while(true)
      {
      Handshake_Type type = HANDSHAKE_NONE;
      SecureVector<byte> contents;

      if(rec_type == HANDSHAKE)
         {
         if(state->queue.size() >= 4)
            {
            byte head[4] = { 0 };
            state->queue.peek(head, 4);

            const size_t length = make_u32bit(0, head[1], head[2], head[3]);

            if(state->queue.size() >= length + 4)
               {
               type = static_cast<Handshake_Type>(head[0]);
               contents.resize(length);
               state->queue.read(head, 4);
               state->queue.read(&contents[0], contents.size());
               }
            }
         }
      else if(rec_type == CHANGE_CIPHER_SPEC)
         {
         if(state->queue.size() == 0 && rec_buf.size() == 1 && rec_buf[0] == 1)
            type = HANDSHAKE_CCS;
         else
            throw Decoding_Error("Malformed ChangeCipherSpec message");
         }
      else
         throw Decoding_Error("Unknown message type in handshake processing");

      if(type == HANDSHAKE_NONE)
         break;

      process_handshake_msg(type, contents);

      if(type == HANDSHAKE_CCS || !state)
         break;
      }
   }
开发者ID:BenjaminSchiborr,项目名称:safe,代码行数:55,代码来源:tls_server.cpp

示例3: encrypt

/*!
    Encrypts \a data using \a password as the passphrase.

    \param data The data to encrypt.
    \param password The passphrase used to encrypt \a data.
    \param compressionLevel The level of compression to use on \a data. See Database::compression.
    \param error If this parameter is non-\c NULL, it will be set to DatabaseCrypto::NoError if the
    encryption process succeeded, or one of the other DatabaseCrypto::CryptoStatus enumeration
    constants if an error occurred.
    \param extendedErrorInformation If this parameter is non-\c NULL, it will be set to a string
    containing detailed information about any errors that occurred.

    \return The encrypted data encoded in base 64, or an empty string if an error occurred.
 */
QString DatabaseCrypto::encrypt(const QString &data, const QString &password, int compressionLevel, CryptoStatus *error, QString *extendedErrorInformation)
{
    const std::string algo = ALGO;
    const QString header = HEADER;

    Botan::LibraryInitializer init;
    Q_UNUSED(init);

    if (error)
    {
        *error = NoError;
    }

    std::string passphrase = password.toStdString();

    // Holds the output data
    QString out;

    try
    {
        const BlockCipher* cipher_proto = global_state().algorithm_factory().prototype_block_cipher(algo);
        const u32bit key_len = cipher_proto->maximum_keylength();
        const u32bit iv_len = cipher_proto->block_size(); // TODO: AES block size is always 128 bit, verify this
        const bool compressed = compressionLevel != 0;
        const u32bit iterations = 8192;

        AutoSeeded_RNG rng;
        SecureVector<Botan::byte> salt(8);
        rng.randomize(&salt[0], salt.size());

        std::auto_ptr<PBKDF> pbkdf(get_pbkdf("PBKDF2(SHA-1)"));
        SymmetricKey bc_key = pbkdf->derive_key(key_len, "BLK" + passphrase, &salt[0], salt.size(), iterations);
        InitializationVector iv = pbkdf->derive_key(iv_len, "IVL" + passphrase, &salt[0], salt.size(), iterations);
        SymmetricKey mac_key = pbkdf->derive_key(16, "MAC" + passphrase, &salt[0], salt.size(), iterations);

        // Write the standard file header and the salt encoded in base64
        out += QString("%1 %2 %3\n").arg(header).arg(Database::version())
               .arg(compressed ? COMPRESSED : UNCOMPRESSED);
        out += QString::fromStdString(b64_encode(salt)) + "\n";

        Pipe pipe(
            new Fork(
                new Chain(
                    new MAC_Filter("HMAC(SHA-1)", mac_key),
                    new Base64_Encoder),
                new Chain(
                    get_cipher(algo + "/CBC/PKCS7", bc_key, iv, ENCRYPTION),
                    new Base64_Encoder(true))));

        // Write our input data to the pipe to process it - if compressionLevel = 0,
        // nothing will be compressed
        pipe.start_msg();
        QByteArray qCompressedData = qCompress(data.toUtf8(), compressionLevel);
        SecureVector<Botan::byte> rawCompressedData;
        rawCompressedData.resize(qCompressedData.length());
        for (int i = 0; i < qCompressedData.length(); i++)
        {
            rawCompressedData[i] = qCompressedData[i];
        }

        pipe.write(rawCompressedData);
        pipe.end_msg();

        // Get the encrypted data back from the pipe and write it to our output variable
        out += QString::fromStdString(pipe.read_all_as_string(0)) + "\n";
        out += QString::fromStdString(pipe.read_all_as_string(1));

        return out;
    }
    catch (Algorithm_Not_Found &e)
    {
        if (extendedErrorInformation)
        {
            *extendedErrorInformation = QString(e.what());
        }

        if (error)
        {
            *error = UnknownError;
        }
    }
    catch (std::exception &e)
    {
        if (extendedErrorInformation)
        {
            *extendedErrorInformation = QString(e.what());
//.........这里部分代码省略.........
开发者ID:petroules,项目名称:silverlock,代码行数:101,代码来源:databasecrypto.cpp

示例4: SetUpBase

	void SetUpBase()
	{
		initial_string_.resize(text_to_encrypt_.size());
		initial_string_.copy(reinterpret_cast<const byte*>(text_to_encrypt_.c_str()), text_to_encrypt_.size());
	}
开发者ID:KoalaComptroller,项目名称:EncryptPad,代码行数:5,代码来源:encryptor_tests.cpp


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