本文整理汇总了C++中ustring::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ ustring::toString方法的具体用法?C++ ustring::toString怎么用?C++ ustring::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ustring
的用法示例。
在下文中一共展示了ustring::toString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: encode
ustring PubAddr::encode(ustring pubKA, ustring privKB , ustring pubKB ,ustring plain)
{
OID CURVE = secp256k1();
AutoSeededRandomPool rng;
ECDH < ECP >::Domain dhA(CURVE), dhB(CURVE);
SecByteBlock privB(privKB.c_str(), dhA.PrivateKeyLength());
SecByteBlock pubA(pubKA.c_str(), dhB.PublicKeyLength());
if (dhA.AgreedValueLength() != dhB.AgreedValueLength())
throw runtime_error("Shared shared size mismatch");
SecByteBlock sharedA(dhA.AgreedValueLength()), sharedB(dhB.AgreedValueLength());
if (!dhA.Agree(sharedA, privB, pubA))
throw runtime_error("Failed to reach shared secret (A)");
Integer ssa, ssb;
ssa.Decode(sharedA.BytePtr(), sharedA.SizeInBytes());
uint8_t H[CryptoPP::SHA512::DIGESTSIZE];
CryptoPP::SHA512 hash;
hash.CalculateDigest(H, sharedA.BytePtr(), sharedA.SizeInBytes());
AutoSeededRandomPool prng;
byte key[32];
memcpy(key, H, sizeof(key));
byte Hkey[32];
memcpy(Hkey, &(H[32]), sizeof(Hkey));
byte iv[16];
prng.GenerateBlock(iv, sizeof(iv));
string SPlain = plain.toString(), encoded;
try
{
CBC_Mode< AES >::Encryption e;
e.SetKeyWithIV(key, sizeof(key), iv);
// The StreamTransformationFilter removes
// padding as required.
StringSource s(SPlain, true,
new StreamTransformationFilter(e,
new StringSink(encoded)
) // StreamTransformationFilter
); // StringSource
}
catch (const CryptoPP::Exception& e)
{
throw runtime_error(e.what());
}
ustring result;
result.append(iv, 16);
result.appendInt16(714);
result.appendInt16(32);
result.append(pubKB.c_str() + 1, 32);
result.appendInt16(32);
result.append(pubKB.c_str() + 33, 32);
result.fromString(encoded);
string HMacPlain;
HMacPlain += result.toString();
string mac;
try
{
HMAC<SHA256> hmac(Hkey, 32);
StringSource s(HMacPlain, true,
new HashFilter(hmac,
new StringSink(mac)
)
);
}
catch (const CryptoPP::Exception& e)
{
throw runtime_error(e.what());
}
result.fromString(mac);
return result;
}