当前位置: 首页>>代码示例>>C++>>正文


C++ SymmetricKey::toString方法代码示例

本文整理汇总了C++中SymmetricKey::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ SymmetricKey::toString方法的具体用法?C++ SymmetricKey::toString怎么用?C++ SymmetricKey::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SymmetricKey的用法示例。


在下文中一共展示了SymmetricKey::toString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: OpensslException

std::vector<unsigned char> Crypto::decryptSymmetric(const SymmetricKey& key, const std::vector<unsigned char>& ciphertext)
{
	Log::writeToLog(Log::L_DEBUG, "Decrypting ciphertext of length ", ciphertext.size(), " with key ", key.toString());
	openssl::EVP_CIPHER_CTX* cipherContext = 0;
	//init context
	if (NULL == (cipherContext = openssl::EVP_CIPHER_CTX_new()))
		throw OpensslException("Couldn't create cipher context");
	if (1 != openssl::EVP_DecryptInit_ex(cipherContext, openssl::EVP_aes_256_cbc(), NULL, key.key.data(), key.iv.data()))
		throw OpensslException("Couldn't init symmetric decryption");

	//do main decryption
	unsigned char * plaintextBuffer = new unsigned char[ciphertext.size() + 1024];

	int usedLength = 0;
	if (1 != openssl::EVP_DecryptUpdate(cipherContext, plaintextBuffer, &usedLength, ciphertext.data(), ciphertext.size()))
		throw OpensslException("Couldn't decrypt ciphertext");

	//finalize decryption. Additional plaintext can be written, so account for it
 	int additionalLength = 0;
	if (1 != openssl::EVP_DecryptFinal(cipherContext, plaintextBuffer + usedLength, &additionalLength))
		throw OpensslException("Couldn't finalize decryption");
	usedLength += additionalLength;
	
	//get result
	std::vector<unsigned char> plaintext = std::vector<unsigned char>(plaintextBuffer, plaintextBuffer + usedLength);
	//cleanup
	openssl::EVP_CIPHER_CTX_free(cipherContext);
	delete[](plaintextBuffer);

	Log::writeToLog(Log::L_DEBUG, "Decrypted into plaintext of length ", plaintext.size());
	
	return plaintext;
}
开发者ID:meson800,项目名称:symmetry,代码行数:33,代码来源:Crypto.cpp


注:本文中的SymmetricKey::toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。