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


C++ KviCString::padRight方法代码示例

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


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

示例1: init

bool KviRijndaelEngine::init(const char * encKey, int encKeyLen, const char * decKey, int decKeyLen)
{
	if(m_pEncryptCipher)
	{
		delete m_pEncryptCipher;
		m_pEncryptCipher = nullptr;
	}
	if(m_pDecryptCipher)
	{
		delete m_pDecryptCipher;
		m_pDecryptCipher = nullptr;
	}

	if(encKey && (encKeyLen > 0))
	{
		if(!(decKey && (decKeyLen > 0)))
		{
			decKey = encKey;
			decKeyLen = encKeyLen;
		} // else all
	}
	else
	{
		// no encrypt key specified...
		if(decKey && decKeyLen)
		{
			encKey = decKey;
			encKeyLen = decKeyLen;
		}
		else
		{
			// both keys missing
			setLastError(__tr2qs("Missing both encryption and decryption key: at least one is needed"));
			return false;
		}
	}

	KviCString szTmpEncryptKey = KviCString(encKey, encKeyLen);
	KviCString szTmpDecryptKey = KviCString(decKey, decKeyLen);

	m_bEncryptMode = CBC; // default mode
	m_bDecryptMode = CBC; // default mode

	if(kvi_strEqualCIN("ecb:", szTmpEncryptKey.ptr(), 4) && (szTmpEncryptKey.len() > 4))
	{
		szTmpEncryptKey.cutLeft(4);
		m_bEncryptMode = ECB;
	}
	else if(kvi_strEqualCIN("old:", szTmpEncryptKey.ptr(), 4) && (szTmpEncryptKey.len() > 4))
	{
		szTmpEncryptKey.cutLeft(4);
		m_bEncryptMode = OldCBC;
	}
	else if(kvi_strEqualCIN("cbc:", szTmpEncryptKey.ptr(), 4) && (szTmpEncryptKey.len() > 4))
	{
		szTmpEncryptKey.cutLeft(4);
	}

	if(kvi_strEqualCIN("ecb:", szTmpDecryptKey.ptr(), 4) && (szTmpDecryptKey.len() > 4))
	{
		szTmpDecryptKey.cutLeft(4);
		m_bDecryptMode = ECB;
	}
	else if(kvi_strEqualCIN("old:", szTmpDecryptKey.ptr(), 4) && (szTmpDecryptKey.len() > 4))
	{
		szTmpDecryptKey.cutLeft(4);
		m_bDecryptMode = OldCBC;
	}
	else if(kvi_strEqualCIN("cbc:", szTmpDecryptKey.ptr(), 4) && (szTmpDecryptKey.len() > 4))
	{
		szTmpDecryptKey.cutLeft(4);
	}

	int defLen = getKeyLen();

	szTmpEncryptKey.padRight(defLen);
	szTmpDecryptKey.padRight(defLen);

	m_pEncryptCipher = new Rijndael();

	int retVal = m_pEncryptCipher->init(
	    (m_bEncryptMode == ECB) ? Rijndael::ECB : Rijndael::CBC,
	    Rijndael::Encrypt,
	    (unsigned char *)szTmpEncryptKey.ptr(),
	    getKeyLenId());
	if(retVal != RIJNDAEL_SUCCESS)
	{
		delete m_pEncryptCipher;
		m_pEncryptCipher = nullptr;
		setLastErrorFromRijndaelErrorCode(retVal);
		return false;
	}

	m_pDecryptCipher = new Rijndael();
	retVal = m_pDecryptCipher->init(
	    (m_bEncryptMode == ECB) ? Rijndael::ECB : Rijndael::CBC,
	    Rijndael::Decrypt,
	    (unsigned char *)szTmpDecryptKey.ptr(),
	    getKeyLenId());
	if(retVal != RIJNDAEL_SUCCESS)
//.........这里部分代码省略.........
开发者ID:CardinalSins,项目名称:KVIrc,代码行数:101,代码来源:libkvirijndael.cpp


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