本文整理汇总了C++中bytes类的典型用法代码示例。如果您正苦于以下问题:C++ bytes类的具体用法?C++ bytes怎么用?C++ bytes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了bytes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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");
}
示例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));
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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++;
}
}
示例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;
}
示例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;
}
示例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))) );
}
示例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);
}
示例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" );
}