本文整理汇总了C++中bytes类的典型用法代码示例。如果您正苦于以下问题:C++ bytes类的具体用法?C++ bytes怎么用?C++ bytes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了bytes类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1:
DatagramEncryptor::DatagramEncryptor(const bytes &encryptionKey, const bytes &IV, const bytes &macKey) :
aesCtr(&IV[0], IV.size(), &encryptionKey[0], encryptionKey.size()),
hmac(sha1, macKey)
{
if (macKey.size() < sha1.outputLen()) throw DsrpException("DatagramEncryptor::DatagramEncryptor: macKey not long enough");
}
开发者ID:SmartActiveNode2,项目名称:san2,代码行数:7,代码来源:datagramencryptor.cpp
示例2: getPushNumber
std::tuple<QList<QObject*>, QQMLMap*> DebuggingStateWrapper::getHumanReadableCode(const bytes& _code, QObject* _objUsedAsParent)
{
QList<QObject*> codeStr;
QMap<int, int> codeMapping;
for (unsigned i = 0; i <= _code.size(); ++i)
{
byte b = i < _code.size() ? _code[i] : 0;
try
{
QString s = QString::fromStdString(instructionInfo((Instruction)b).name);
std::ostringstream out;
out << std::hex << std::setw(4) << std::setfill('0') << i;
codeMapping[i] = codeStr.size();
int line = i;
if (b >= (byte)Instruction::PUSH1 && b <= (byte)Instruction::PUSH32)
{
unsigned bc = getPushNumber((Instruction)b);
s = "PUSH 0x" + QString::fromStdString(toHex(bytesConstRef(&_code[i + 1], bc)));
i += bc;
}
HumanReadableCode* humanCode = new HumanReadableCode(QString::fromStdString(out.str()) + " " + s, line, _objUsedAsParent);
codeStr.append(humanCode);
}
catch (...)
{
qDebug() << QString("Unhandled exception!") << endl <<
QString::fromStdString(boost::current_exception_diagnostic_information());
break; // probably hit data segment
}
}
return std::make_tuple(codeStr, new QQMLMap(codeMapping, _objUsedAsParent));
}
开发者ID:caktux,项目名称:cpp-ethereum,代码行数:32,代码来源:DebuggingStateWrapper.cpp
示例3: ctr
bytes Secp256k1PP::eciesKDF(Secret const& _z, bytes _s1, unsigned kdByteLen)
{
auto reps = ((kdByteLen + 7) * 8) / (CryptoPP::SHA256::BLOCKSIZE * 8);
// SEC/ISO/Shoup specify counter size SHOULD be equivalent
// to size of hash output, however, it also notes that
// the 4 bytes is okay. NIST specifies 4 bytes.
bytes ctr({0, 0, 0, 1});
bytes k;
CryptoPP::SHA256 ctx;
for (unsigned i = 0; i <= reps; i++)
{
ctx.Update(ctr.data(), ctr.size());
ctx.Update(_z.data(), Secret::size);
ctx.Update(_s1.data(), _s1.size());
// append hash to k
bytes digest(32);
ctx.Final(digest.data());
ctx.Restart();
k.reserve(k.size() + h256::size);
move(digest.begin(), digest.end(), back_inserter(k));
if (++ctr[3] || ++ctr[2] || ++ctr[1] || ++ctr[0])
continue;
}
k.resize(kdByteLen);
return k;
}
开发者ID:asadsalman,项目名称:ring-daemon,代码行数:29,代码来源:CryptoPP.cpp
示例4: parse
void Packet::parse(bytes data) {
memcpy(&head[0], &data[0], HEADER_LEN);
body.resize(data.size() - HEADER_LEN);
memcpy(&body[0], &data[HEADER_LEN], data.size() - HEADER_LEN);
int i = 0;
short checkLen = 0x0;
pull(head, i, version);
pull(head, i, opCode);
pull(head, i, switchMac);
pull(head, i, hostMac);
pull(head, i, sequenceId);
pull(head, i, errorCode);
pull(head, i, checkLen);
pull(head, i, fragmentOffset);
pull(head, i, flag);
pull(head, i, tokenId);
pull(head, i, checkSum);
if (this->getLength() != checkLen) {
printf("Packet Length doesn't match: %lu != %hd\n", data.size(),
checkLen);
}
i = 0;
dataset d;
payload = {};
while (i < (int) body.size() - 4) {
pull(body, i, d.type);
pull(body, i, d.len);
pull(body, i, d.value, d.len);
payload.push_back(d);
}
}
开发者ID:jed1,项目名称:smrtlink,代码行数:31,代码来源:Packet.cpp
示例5: kdf
bytes ecies::kdf(Secret const& _z, bytes const& _s1, unsigned kdByteLen)
{
auto reps = ((kdByteLen + 7) * 8) / 512;
// SEC/ISO/Shoup specify counter size SHOULD be equivalent
// to size of hash output, however, it also notes that
// the 4 bytes is okay. NIST specifies 4 bytes.
std::array<byte, 4> ctr{{0, 0, 0, 1}};
bytes k;
secp256k1_sha256_t ctx;
for (unsigned i = 0; i <= reps; i++)
{
secp256k1_sha256_initialize(&ctx);
secp256k1_sha256_write(&ctx, ctr.data(), ctr.size());
secp256k1_sha256_write(&ctx, _z.data(), Secret::size);
secp256k1_sha256_write(&ctx, _s1.data(), _s1.size());
// append hash to k
std::array<byte, 32> digest;
secp256k1_sha256_finalize(&ctx, digest.data());
k.reserve(k.size() + h256::size);
move(digest.begin(), digest.end(), back_inserter(k));
if (++ctr[3] || ++ctr[2] || ++ctr[1] || ++ctr[0])
continue;
}
k.resize(kdByteLen);
return k;
}
开发者ID:ethereum,项目名称:cpp-ethereum,代码行数:29,代码来源:Common.cpp
示例6: l
void Secp256k1PP::encrypt(Public const& _k, bytes& io_cipher)
{
auto& ctx = Secp256k1PPCtx::get();
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
CryptoPP::ECIES<CryptoPP::ECP>::Encryptor e;
#pragma GCC diagnostic pop
#pragma clang diagnostic pop
{
Guard l(ctx.x_params);
e.AccessKey().Initialize(ctx.m_params, publicToPoint(_k));
}
size_t plen = io_cipher.size();
bytes ciphertext;
ciphertext.resize(e.CiphertextLength(plen));
{
Guard l(ctx.x_rng);
e.Encrypt(ctx.m_rng, io_cipher.data(), plen, ciphertext.data());
}
memset(io_cipher.data(), 0, io_cipher.size());
io_cipher = std::move(ciphertext);
}
开发者ID:Kingefosa,项目名称:cpp-microdatachain,代码行数:30,代码来源:CryptoPP.cpp
示例7: setw
string dev::memDump(bytes const& _bytes, unsigned _width, bool _html)
{
stringstream ret;
if (_html)
ret << "<pre style=\"font-family: Monospace,Lucida Console,Courier,Courier New,sans-serif; font-size: small\">";
for (unsigned i = 0; i < _bytes.size(); i += _width)
{
ret << hex << setw(4) << setfill('0') << i << " ";
for (unsigned j = i; j < i + _width; ++j)
if (j < _bytes.size())
if (_bytes[j] >= 32 && _bytes[j] < 127)
if ((char)_bytes[j] == '<' && _html)
ret << "<";
else if ((char)_bytes[j] == '&' && _html)
ret << "&";
else
ret << (char)_bytes[j];
else
ret << '?';
else
ret << ' ';
ret << " ";
for (unsigned j = i; j < i + _width && j < _bytes.size(); ++j)
ret << setfill('0') << setw(2) << hex << (unsigned)_bytes[j] << " ";
ret << "\n";
}
if (_html)
ret << "</pre>";
return ret.str();
}
开发者ID:285452612,项目名称:bcos,代码行数:30,代码来源:CommonIO.cpp
示例8: eciesKDF
void Secp256k1PP::encryptECIES(Public const& _k, bytesConstRef _sharedMacData, bytes& io_cipher)
{
// interop w/go ecies implementation
auto r = KeyPair::create();
Secret z;
ecdh::agree(r.sec(), _k, z);
auto key = eciesKDF(z, bytes(), 32);
bytesConstRef eKey = bytesConstRef(&key).cropped(0, 16);
bytesRef mKeyMaterial = bytesRef(&key).cropped(16, 16);
CryptoPP::SHA256 ctx;
ctx.Update(mKeyMaterial.data(), mKeyMaterial.size());
bytes mKey(32);
ctx.Final(mKey.data());
bytes cipherText = encryptSymNoAuth(SecureFixedHash<16>(eKey), h128(), bytesConstRef(&io_cipher));
if (cipherText.empty())
return;
bytes msg(1 + Public::size + h128::size + cipherText.size() + 32);
msg[0] = 0x04;
r.pub().ref().copyTo(bytesRef(&msg).cropped(1, Public::size));
bytesRef msgCipherRef = bytesRef(&msg).cropped(1 + Public::size + h128::size, cipherText.size());
bytesConstRef(&cipherText).copyTo(msgCipherRef);
// tag message
CryptoPP::HMAC<SHA256> hmacctx(mKey.data(), mKey.size());
bytesConstRef cipherWithIV = bytesRef(&msg).cropped(1 + Public::size, h128::size + cipherText.size());
hmacctx.Update(cipherWithIV.data(), cipherWithIV.size());
hmacctx.Update(_sharedMacData.data(), _sharedMacData.size());
hmacctx.Final(msg.data() + 1 + Public::size + cipherWithIV.size());
io_cipher.resize(msg.size());
io_cipher.swap(msg);
}
开发者ID:asadsalman,项目名称:ring-daemon,代码行数:34,代码来源:CryptoPP.cpp
示例9: pushLocation
static void pushLocation(bytes& o_code, uint32_t _locationValue)
{
o_code.push_back((byte)Instruction::PUSH4);
o_code.resize(o_code.size() + 4);
bytesRef r(&o_code[o_code.size() - 4], 4);
toBigEndian(_locationValue, r);
}
开发者ID:AcriCAA,项目名称:cpp-ethereum,代码行数:7,代码来源:Instruction.cpp
示例10: push
void Packet::push(bytes &arr, int &index, byte data) {
if (arr.size() > (unsigned) index) {
arr[index++] = data;
} else {
arr.push_back(data);
index++;
}
}
开发者ID:jed1,项目名称:smrtlink,代码行数:8,代码来源:Packet.cpp
示例11: pushLiteral
static unsigned pushLiteral(bytes& o_code, u256 _literalValue)
{
unsigned br = max<unsigned>(1, bytesRequired(_literalValue));
o_code.push_back((byte)Instruction::PUSH1 + br - 1);
o_code.resize(o_code.size() + br);
for (unsigned i = 0; i < br; ++i)
{
o_code[o_code.size() - 1 - i] = (byte)(_literalValue & 0xff);
_literalValue >>= 8;
}
return br + 1;
}
开发者ID:AcriCAA,项目名称:cpp-ethereum,代码行数:12,代码来源:Instruction.cpp
示例12: unpadLeft
bytes unpadLeft(bytes _b)
{
unsigned int i = 0;
if (_b.size() == 0)
return _b;
while (i < _b.size() && _b[i] == byte(0))
i++;
if (i != 0)
_b.erase(_b.begin(), _b.begin() + i);
return _b;
}
开发者ID:superbitcoin,项目名称:SuperBitcoin,代码行数:13,代码来源:CommonJS.cpp
示例13: FC_ASSERT
bytes public_key::decrypt( const bytes& in )const
{
FC_ASSERT( my && my->rsa );
bytes out( RSA_size(my->rsa) );//, char(0) );
int rtn = RSA_public_decrypt( in.size(),
(unsigned char*)in.data(),
(unsigned char*)out.data(),
my->rsa, RSA_PKCS1_OAEP_PADDING );
if( rtn >= 0 ) {
out.resize(rtn);
return out;
}
FC_THROW_EXCEPTION( exception, "openssl: ${message}", ("message",fc::string(ERR_error_string( ERR_get_error(),NULL))) );
}
开发者ID:FollowMyVote,项目名称:fc,代码行数:14,代码来源:pke.cpp
示例14:
public_key::public_key( const bytes& d )
:my( std::make_shared<detail::pke_impl>() )
{
string pem = "-----BEGIN RSA PUBLIC KEY-----\n";
auto b64 = fc::base64_encode( (const unsigned char*)d.data(), d.size() );
for( size_t i = 0; i < b64.size(); i += 64 )
pem += b64.substr( i, 64 ) + "\n";
pem += "-----END RSA PUBLIC KEY-----\n";
// fc::cerr<<pem;
BIO* mem = (BIO*)BIO_new_mem_buf( (void*)pem.c_str(), pem.size() );
my->rsa = PEM_read_bio_RSAPublicKey(mem, NULL, NULL, NULL );
BIO_free(mem);
}
开发者ID:FollowMyVote,项目名称:fc,代码行数:14,代码来源:pke.cpp
示例15: decrypt
bytes private_key::decrypt( const bytes& in )const
{
if( !my ) FC_THROW_EXCEPTION( assert_exception, "!null" );
bytes out;
out.resize( RSA_size(my->rsa) );
int rtn = RSA_private_decrypt( in.size(),
(unsigned char*)in.data(),
(unsigned char*)out.data(),
my->rsa, RSA_PKCS1_OAEP_PADDING );
if( rtn >= 0 ) {
out.resize(rtn);
return out;
}
FC_THROW_EXCEPTION( exception, "decrypt failed" );
}
开发者ID:FollowMyVote,项目名称:fc,代码行数:15,代码来源:pke.cpp
示例16: ret
bytesSec dev::pbkdf2(string const& _pass, bytes const& _salt, unsigned _iterations, unsigned _dkLen)
{
bytesSec ret(_dkLen);
if (PKCS5_PBKDF2_HMAC<SHA256>().DeriveKey(
ret.writable().data(),
_dkLen,
0,
reinterpret_cast<byte const*>(_pass.data()),
_pass.size(),
_salt.data(),
_salt.size(),
_iterations
) != _iterations)
BOOST_THROW_EXCEPTION(CryptoException() << errinfo_comment("Key derivation failed."));
return ret;
}
开发者ID:AndresAH,项目名称:cpp-ethereum,代码行数:16,代码来源:Common.cpp
示例17: getSessionKey
bytes SrpClientAuthenticator::getSessionKey(bytes M2_from_server)
{
if (M2_from_server.size() == 0) throw DsrpException("SrpClientAuthenticator::getSessionKey: M2_from_server.size() == 0");
if (M2_calculated.size() == 0) throw DsrpException("SrpClientAuthenticator::getSessionKey: M2_calculated.size() == 0");
if (M2_from_server != M2_calculated) throw DsrpException("Authentification failed, bad password");
return K;
}
开发者ID:SmartActiveNode2,项目名称:san2,代码行数:7,代码来源:srpclientauthenticator.cpp
示例18: zlib_decompress_context_free_data
static vector<bytes> zlib_decompress_context_free_data(const bytes& data) {
if( data.size() == 0 )
return vector<bytes>();
bytes out = zlib_decompress(data);
return unpack_context_free_data(out);
}
开发者ID:BestSilent,项目名称:eos,代码行数:7,代码来源:transaction.cpp
示例19: beginsWith
bool beginsWith(Address _a, bytes const& _b)
{
for (unsigned i = 0; i < min<unsigned>(20, _b.size()); ++i)
if (_a[i] != _b[i])
return false;
return true;
}
开发者ID:EarthDollar,项目名称:farmer,代码行数:7,代码来源:NewAccount.cpp
示例20: onGamecomponentEvent
void LmRightSpotScene::onGamecomponentEvent(bytes l_oMsg)
{
int idGameComponent = l_oMsg.readInt();
layerChildReceive(idGameComponent);
}
开发者ID:ludomuse,项目名称:totalproject,代码行数:7,代码来源:LmRightSpotScene.cpp
注:本文中的bytes类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论