本文整理汇总了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;
}