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


C++ cryptopp::SHA1类代码示例

本文整理汇总了C++中cryptopp::SHA1的典型用法代码示例。如果您正苦于以下问题:C++ SHA1类的具体用法?C++ SHA1怎么用?C++ SHA1使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: asLowerCaseString

std::string transformToSHA1(std::string plainText, bool upperCase)
{
	// Crypto++ SHA1 object
	CryptoPP::SHA1 hash;

	// Use native byte instead of casting chars
	byte digest[CryptoPP::SHA1::DIGESTSIZE];

	// Do the actual calculation, require a byte value so we need a cast
	hash.CalculateDigest(digest, (const byte*)plainText.c_str(), plainText.length());

	// Crypto++ HexEncoder object
	CryptoPP::HexEncoder encoder;

	// Our output
	std::string output;

	// Drop internal hex encoder and use this, returns uppercase by default
	encoder.Attach(new CryptoPP::StringSink(output));
	encoder.Put(digest, sizeof(digest));
	encoder.MessageEnd();

	// Make sure we want uppercase
	if(upperCase)
		return output;

	// Convert to lowercase if needed
	return asLowerCaseString(output);
}
开发者ID:AhmedWaly,项目名称:CastOnly,代码行数:29,代码来源:tools.cpp

示例2:

//***************************************************************
byte * HashClass::getSHA1(const byte * input, int length)
{
    CryptoPP::SHA1 sha;
    byte *digest = new byte [CryptoPP::SHA1::DIGESTSIZE];
    sha.CalculateDigest(digest, input, length);
    return digest;
}
开发者ID:MutualChipAuthentication,项目名称:MobileAKE,代码行数:8,代码来源:HashClass.cpp

示例3: MakeParameters

void cProtocol132::StartEncryption(const byte * a_Key)
{
	m_Encryptor.SetKey(a_Key, 16, MakeParameters(Name::IV(), ConstByteArrayParameter(a_Key, 16))(Name::FeedbackSize(), 1));
	m_Decryptor.SetKey(a_Key, 16, MakeParameters(Name::IV(), ConstByteArrayParameter(a_Key, 16))(Name::FeedbackSize(), 1));
	m_IsEncrypted = true;
	
	// Prepare the m_AuthServerID:
	CryptoPP::SHA1 Checksum;
	AString ServerID = cRoot::Get()->GetServer()->GetServerID();
	Checksum.Update((const byte *)ServerID.c_str(), ServerID.length());
	Checksum.Update(a_Key, 16);
	Checksum.Update((const byte *)m_ServerPublicKey.c_str(), m_ServerPublicKey.length());
	byte Digest[20];
	Checksum.Final(Digest);
	DigestToJava(Digest, m_AuthServerID);
}
开发者ID:l0ud,项目名称:MCServer,代码行数:16,代码来源:Protocol132.cpp

示例4: HashCalculate

/*Calculate SHA1 hash*/
string HashCalculate(string input_string)
{
	CryptoPP::SHA1 hash;
	byte digest[CryptoPP::SHA1::DIGESTSIZE];
	string output;

	//calculate hash
	hash.CalculateDigest(digest, (const byte *)input_string.c_str(),
                         input_string.size());

	//encode in Hex
	CryptoPP::HexEncoder encoder;
	CryptoPP::StringSink *SS = new CryptoPP::StringSink(output);
	encoder.Attach(SS);
	encoder.Put(digest, sizeof(digest));
	encoder.MessageEnd();

	//prepend 0x
	output = "0x" + output;
	return output;
}
开发者ID:apuljain,项目名称:ZKP,代码行数:22,代码来源:CommonFunctions.cpp

示例5: updateHash

 void updateHash(CryptoPP::SHA1 & hash, uint8_t *buf, int width, int height, int stride) {
    for(int i = 0; i < height; i++)
      hash.Update(buf + i * stride, width);
 }
开发者ID:kali2,项目名称:openh264,代码行数:4,代码来源:decoder_test.cpp

示例6: OnOK

void CPropChkSum::OnOK() 
{
	UpdateData();

	CPropertyPage::OnOK();
	if(m_szFileName == _T("")) {
		AfxMessageBox(_T("Please select the file."));
		return ;
	}

	HANDLE hFile = CreateFile(m_szFileName, GENERIC_WRITE | GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,NULL);
	if (hFile == INVALID_HANDLE_VALUE){
		CString str = m_szFileName + _T(" doesn't exist!");
		AfxMessageBox(str);
		return ;
	}

	DWORD dwFileSize = GetFileSize(hFile, NULL);
	HANDLE hFileMap = CreateFileMapping(
						hFile, // 如果这值为INVALID_HANDLE_VALUE,是合法的,上步一定测试啊
						NULL,    // 默认安全性
						PAGE_READWRITE,    // 可读
						0, // 2个32位数示1个64位数,最大文件字节数,
						 // 高字节,文件大小小于4G时,高字节永远为0
						0,//dwFileSize, // 此为低字节,也就是最主要的参数,如果为0,取文件真实大小
						NULL);
	if (hFileMap == NULL)
	{
		CString str = _T("Mapping ") + m_szFileName + _T(" failed!");
		AfxMessageBox(str);
		CloseHandle(hFile);
		return ;
	}

	PVOID pvFile = MapViewOfFile( //pvFile就是得到的指针,用它来直接操作文件
						hFileMap, 
						FILE_MAP_WRITE,     // 可读
						0,      // 文件指针头位置 高字节
						0, // 文件指针头位置 低字节 必为分配粒度的整倍数,windows的粒度为64K
						0);    // 要映射的文件尾,如果为0,则从指针头到真实文件尾
	if (pvFile == NULL)	{
		CString str = _T("MapViewOfFile ") + m_szFileName + _T(" failed, ERROR:!");
		str.Format(_T("MapViewOfFile %s failed, ERROR:%d!"), m_szFileName, GetLastError());
		AfxMessageBox(str);
		CloseHandle(hFileMap);
		CloseHandle(hFile);
		return ;
	}
	// 步骤4: 像操作内存一样操作文件,演示功能把整个文件倒序
	char *pData = (char*)pvFile;

	boost::crc_16_type crc16t;
	crc16t.process_bytes(pData, dwFileSize);
	unsigned short crc16 = crc16t.checksum();
	m_strCRC16.Format(_T("%04X"), crc16);

	boost::crc_ccitt_type crc_ccitt;
	crc_ccitt.process_bytes(pData, dwFileSize);
	crc16 = crc_ccitt.checksum();
	m_strCRC_CCITT.Format(_T("%04X"), crc16);

	boost::crc_xmodem_type  crc_xmdm;
	crc_xmdm.process_bytes(pData, dwFileSize);
	crc16 = crc_xmdm.checksum();
	m_strCRC32C.Format(_T("%04X"), crc16);

	boost::crc_32_type crc32t;
	crc32t.process_bytes(pData, dwFileSize);
	unsigned long crc32 = crc32t.checksum();
	m_strCRC32.Format(_T("%04X"), crc32);

	enum {
		MessageDigest_MD5 = 0,
		MessageDigest_SHA,
		MessageDigest_SHA1,
		MessageDigest_SHA224,
		MessageDigest_SHA256,
		MessageDigest_SHA384,
		MessageDigest_SHA3_224,
		MessageDigest_SHA3_256,
		MessageDigest_SHA3_384,
		MessageDigest_SHA3_512
	};
	
	CString strMessageDigest;
	unsigned char sha_md[120] = {0};
	int index = 0;

	if(m_mdList.GetCheck(MessageDigest_MD5)) {
		CryptoPP::Weak1::MD5 md5;
		md5.CalculateDigest((byte*)&sha_md, (unsigned char *)pData, dwFileSize);
		strMessageDigest.Format( 
			"MD5: %02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X",
			sha_md[0], sha_md[1], sha_md[2], sha_md[3],sha_md[4], sha_md[5], sha_md[6], sha_md[7], 
			sha_md[8], sha_md[9], sha_md[10], sha_md[11],sha_md[12], sha_md[13], sha_md[14], sha_md[15]
		);
		
		m_mdList.SetItemText(MessageDigest_MD5, 0, strMessageDigest);
	}
//.........这里部分代码省略.........
开发者ID:shagpg2008,项目名称:SmallToolKit,代码行数:101,代码来源:PropChkSum.cpp

示例7: coumpute_authcode

void Token::coumpute_authcode(BYTE challenge[8], BYTE rte_data[20]){
	BYTE static_rte64[64],
		response[8], //result
		data[64],
		rte_data64[64],
		digest[20],
		key_3des_24[24],
		magic_sum_out64[64];

	int pass_len = strlen(this->upass),
		pass_len_u = 2 * (pass_len + 1); //in UTF-8

	BYTE *token_pass_u = new BYTE[pass_len_u];
	memset(token_pass_u, 0, pass_len_u);

	for (int i = 0; i < pass_len; i++){
		token_pass_u[i * 2] = 0;
		token_pass_u[i * 2 + 1] = this->upass[i];
	}
	token_pass_u[pass_len * 2] = token_pass_u[pass_len * 2 + 1] = 0;
	//cout << "token_pass_u "; showarr(token_pass_u, pass_len_u, ':'); //DEBUG

	for (int i = 0; i < 64; i++){
		static_rte64[i] = 0x03;
		data[i] = token_pass_u[i % pass_len_u];
		rte_data64[i] = rte_data[i % 20];
	}

	//cout << "rte_data64 "; showarr(rte_data64, 64, ':'); //DEBUG
	//cout << "static_rte64 "; showarr(static_rte64, 64, ':'); //DEBUG
	//cout << "data "; showarr(data, 64, ':'); //DEBUG

	CryptoPP::SHA1 h;
	h.Update(static_rte64, 64);
	h.Update(rte_data64, 64);
	h.Update(data, 64);
	h.Final(digest);

	//cout << "1st digest "; showarr(digest, 20, ':'); //DEBUG

	for (int i = 0; i < 998; i++){
		CryptoPP::SHA1 h_cycle;
		h_cycle.Update(digest, 20);
		h_cycle.Final(digest);
	}

	memcpy(key_3des_24, digest, 20); //now we have 20 bytes of key, we need 4 bytes more

	h.Restart();
	h.Update(static_rte64, 64);

	this->magic_sum64(magic_sum_out64, digest, rte_data64);
	h.Update(magic_sum_out64, 64);

	this->magic_sum64(magic_sum_out64, digest, data);
	h.Update(magic_sum_out64, 64);

	h.Final(digest);

	for (int i = 0; i < 998; i++){
		CryptoPP::SHA1 h_cycle;
		h_cycle.Update(digest, 20);
		h_cycle.Final(digest);
	}

	memcpy(key_3des_24 + 20, digest, 4); //add remaining 4 bytes, now we have complete key
	//cout << "DES-EDE24 key "; showarr(key_3des_24, 24, ':'); //DEBUG

	//DES-EDE24
	//CryptoPP::DES_EDE3::Encryption e(key_3des_24, CryptoPP::DES_EDE3::DEFAULT_KEYLENGTH);
	//CryptoPP::ECB_Mode_ExternalCipher::Encryption ecb(e);
	CryptoPP::ECB_Mode<CryptoPP::DES_EDE3>::Encryption ecb(key_3des_24, CryptoPP::DES_EDE3::DEFAULT_KEYLENGTH);
	ecb.ProcessData(response, challenge, 8);
	memcpy(challenge, response, 8);

	delete[] token_pass_u;
}
开发者ID:12019,项目名称:Antitoken,代码行数:77,代码来源:Token.cpp


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