本文整理汇总了C++中CryptoBuffer::Slice方法的典型用法代码示例。如果您正苦于以下问题:C++ CryptoBuffer::Slice方法的具体用法?C++ CryptoBuffer::Slice怎么用?C++ CryptoBuffer::Slice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CryptoBuffer
的用法示例。
在下文中一共展示了CryptoBuffer::Slice方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EncryptWithCtr
/**
* Windows doesn't expose CTR mode. We can however, build it manually from ECB. Here, split each
* buffer into 16 byte chunks, for each complete buffer encrypt the counter and xor it against the unencrypted
* text. Save anything left over for the next run.
*/
CryptoBuffer AES_CTR_Cipher_BCrypt::EncryptWithCtr(const CryptoBuffer& buffer)
{
size_t bytesWritten = 0;
Aws::Vector<ByteBuffer*> finalBufferSet(0);
CryptoBuffer bufferToEncrypt;
if (m_blockOverflow.GetLength() > 0 && &m_blockOverflow != &buffer)
{
bufferToEncrypt = CryptoBuffer({ (ByteBuffer*)&m_blockOverflow, (ByteBuffer*)&buffer });
m_blockOverflow = CryptoBuffer();
}
else
{
bufferToEncrypt = buffer;
}
Aws::Utils::Array<CryptoBuffer> slicedBuffers;
if (bufferToEncrypt.GetLength() > BlockSizeBytes)
{
slicedBuffers = bufferToEncrypt.Slice(BlockSizeBytes);
}
else
{
slicedBuffers = Aws::Utils::Array<CryptoBuffer>(1u);
slicedBuffers[0] = bufferToEncrypt;
}
finalBufferSet = Aws::Vector<ByteBuffer*>(slicedBuffers.GetLength());
InitBuffersToNull(finalBufferSet);
for (size_t i = 0; i < slicedBuffers.GetLength(); ++i)
{
if (slicedBuffers[i].GetLength() == BlockSizeBytes || (m_blockOverflow.GetLength() > 0 && slicedBuffers.GetLength() == 1))
{
ULONG lengthWritten = static_cast<ULONG>(BlockSizeBytes);
CryptoBuffer encryptedText(BlockSizeBytes);
NTSTATUS status = BCryptEncrypt(m_keyHandle, m_workingIv.GetUnderlyingData(), (ULONG)m_workingIv.GetLength(),
nullptr, nullptr, 0, encryptedText.GetUnderlyingData(), (ULONG)encryptedText.GetLength(), &lengthWritten, m_flags);
if (!NT_SUCCESS(status))
{
m_failure = true;
AWS_LOGSTREAM_ERROR(CTR_LOG_TAG, "Failed to compute encrypted output with error code " << status);
CleanupBuffers(finalBufferSet);
return CryptoBuffer();
}
CryptoBuffer* newBuffer = Aws::New<CryptoBuffer>(CTR_LOG_TAG, BlockSizeBytes);
*newBuffer = slicedBuffers[i] ^ encryptedText;
finalBufferSet[i] = newBuffer;
IncrementCounter(m_workingIv);
bytesWritten += static_cast<size_t>(lengthWritten);
}
else
{
m_blockOverflow = slicedBuffers[i];
CryptoBuffer* newBuffer = Aws::New<CryptoBuffer>(CTR_LOG_TAG, 0);
finalBufferSet[i] = newBuffer;
}
}
CryptoBuffer returnBuffer(std::move(finalBufferSet));
CleanupBuffers(finalBufferSet);
return returnBuffer;
}