本文整理汇总了C++中OTEnvelope::GetCiphertext方法的典型用法代码示例。如果您正苦于以下问题:C++ OTEnvelope::GetCiphertext方法的具体用法?C++ OTEnvelope::GetCiphertext怎么用?C++ OTEnvelope::GetCiphertext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OTEnvelope
的用法示例。
在下文中一共展示了OTEnvelope::GetCiphertext方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Encrypt
// static
bool LegacySymmetric::Encrypt(
const LegacySymmetric& theKey,
const String& strPlaintext,
String& strOutput,
const String& pstrDisplay,
bool bBookends,
const OTPassword* pAlreadyHavePW)
{
if (!theKey.IsGenerated()) {
LogDetail(OT_METHOD)(__FUNCTION__)(
": Failure: theKey.IsGenerated() was false. (The calling "
"code probably should have checked that key already...).")
.Flush();
return false;
}
if (!strPlaintext.Exists()) {
LogDetail(OT_METHOD)(__FUNCTION__)(
": Plaintext is empty. Please supply. (Failure).")
.Flush();
return false;
}
// By this point, we know we have a plaintext and a symmetric Key.
//
std::unique_ptr<OTPassword> pPassUserInput;
if (nullptr == pAlreadyHavePW) {
const char* szDisplay = "Password-protecting a plaintext.";
const auto strDisplay = String::Factory(
(!pstrDisplay.Exists()) ? szDisplay : pstrDisplay.Get());
pPassUserInput.reset(
GetPassphraseFromUser(strDisplay)); // bAskTwice=false
// by default.
} else
pPassUserInput.reset(new OTPassword(*pAlreadyHavePW));
auto ascOutput = Armored::Factory();
bool bSuccess = false;
if (nullptr != pPassUserInput) // Success retrieving the passphrase from
// the user. (Now let's encrypt...)
{
OTEnvelope theEnvelope;
if (theEnvelope.Encrypt(
strPlaintext,
const_cast<LegacySymmetric&>(theKey),
*pPassUserInput) &&
theEnvelope.GetCiphertext(ascOutput)) {
bSuccess = true;
if (bBookends) {
return ascOutput->WriteArmoredString(
strOutput,
"SYMMETRIC MSG", // todo hardcoding.
false); // bEscaped=false
} else {
strOutput.Set(ascOutput->Get());
}
} else {
LogDetail(OT_METHOD)(__FUNCTION__)(
": Failed trying to encrypt. (Sorry).")
.Flush();
}
} else
LogDetail(OT_METHOD)(__FUNCTION__)(
": Sorry, unable to retrieve passphrase from user. (Failure).")
.Flush();
return bSuccess;
}