本文整理汇总了C++中SecureString::GetPlaintext方法的典型用法代码示例。如果您正苦于以下问题:C++ SecureString::GetPlaintext方法的具体用法?C++ SecureString::GetPlaintext怎么用?C++ SecureString::GetPlaintext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SecureString
的用法示例。
在下文中一共展示了SecureString::GetPlaintext方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsPasswordUpdated
bool SecurityUser::IsPasswordUpdated(SecurityUserSPtr const & other)
{
bool needUpdate = false;
if(this->AccountType == SecurityPrincipalAccountType::DomainUser)
{
if(other)
{
wstring originalPswd = password_;
wstring currentPswd = other->Password;
if(this->isPasswordEncrypted_)
{
SecureString pswd;
CryptoUtility::DecryptText(password_, pswd);
originalPswd = pswd.GetPlaintext();
}
if(other->isPasswordEncrypted_)
{
SecureString pswd;
CryptoUtility::DecryptText(other->password_, pswd);
currentPswd = pswd.GetPlaintext();
}
needUpdate = (originalPswd != currentPswd);
originalPswd.clear();
currentPswd.clear();
}
}
return needUpdate;
}
示例2: GeneratePasswordForNTLMAuthenticatedUser
ErrorCode AccountHelper::GeneratePasswordForNTLMAuthenticatedUser(wstring const& accountName, SecureString const & passwordSecret, __inout SecureString & password)
{
#if defined(PLATFORM_UNIX)
wstring str = move(accountName + passwordSecret.GetPlaintext());
auto hashInput = StringToByteBuffer(str);
SecureZeroMemory((void*)str.c_str(), str.size() * sizeof(wchar_t));
ByteBuffer hashedData;
auto errorCode = LinuxCryptUtil().ComputeHash(hashInput, hashedData);
SecureZeroMemory(hashInput.data(), hashInput.size());
if (!errorCode.IsSuccess()) return errorCode;
#else
// TODO: improve password generation by using a secret
HCRYPTPROV hCryptProv = NULL;
HCRYPTHASH hHash = NULL;
BOOL result = CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT);
KFinally([=] { if(hCryptProv) CryptReleaseContext(hCryptProv, 0); });
if(result)
{
result = CryptCreateHash(hCryptProv, CALG_SHA_512, 0, 0, &hHash);
}
KFinally([=] { if (hHash) CryptDestroyHash(hHash); });
if(result)
{
wstring hashData = move(accountName + passwordSecret.GetPlaintext());
result = CryptHashData(hHash, (BYTE *)hashData.c_str(), (DWORD)hashData.size() * sizeof(WCHAR), 0);
SecureZeroMemory((void *)hashData.c_str(), hashData.size() * sizeof(WCHAR));
}
DWORD dataSize = 0;
DWORD dataSizeLength = sizeof(dataSize);
if(result)
{
result = CryptGetHashParam(hHash, HP_HASHSIZE, (BYTE *)&dataSize, &dataSizeLength, 0);
}
vector<BYTE> hashedData(dataSize);
if(result)
{
ASSERT_IF(dataSize == 0, "dataSize should be set to a positive value");
result = CryptGetHashParam(hHash, HP_HASHVAL, hashedData.data(), &dataSize, 0);
if(!result)
{
Common::Assert::CodingError("Unable to retrieve hash value from the crypt framework");
}
}
else
{
TraceWarning(
TraceTaskCodes::Common,
TraceType_AccountHelper,
"Error generating password");
return ErrorCodeValue::OperationFailed;
}
#endif
wstring value;
StringWriter writer(value);
writer.Write("{0}", PasswordPrefix);
for(auto it = hashedData.begin(); it != hashedData.end(); ++it)
{
writer.Write("{0:x}", (*it));
}
password = SecureString(move(value));
return ErrorCodeValue::Success;
}